- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script error
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 08:47 PM
02-08-2004 08:47 PM
----
-----
read option
[ !-n $option ]
do
----
----
done
This works properly but gives the following error
iq.sh[23]: test: argument expected
If I hit enter the script is exited otherwise a serial number is entered and used in an sql script. The results are correct except for the error being displayed.
Redgards,
John.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 08:50 PM
02-08-2004 08:50 PM
Re: Script error
do
--
--
done
fi
OR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 08:51 PM
02-08-2004 08:51 PM
Re: Script error
Hence the error message.
May be the logic should be reviewed
(inititialise option with an "invalid" option value)
regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 08:58 PM
02-08-2004 08:58 PM
Re: Script error
Until
The until construct is basically the same as the while construct except that the commands in the loop are executed until the conditions are true (instead of false like in the while loop). Here is the format:
until command-list1
do
command-list2
done
If the last command in command-list1 is unsuccessful, then the commands in command-list2 are executed. When the last command in command-list1 is successful, the until loop is terminated. Let's use the same operation in the while section to illustrate:
until [ ! -r $1 ]
do
cat $1 >> composite
done
Notice the subtle difference with the while loop. The ! negates the test conditions. We execute the loop until the condition is true (or successful). The while loop executes the commands while a condition is true (or successful).
http://docs.hp.com/hpux/onlinedocs/B2355-90046/B2355-90046.html
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 09:04 PM
02-08-2004 09:04 PM
SolutionA classic though ugly solution would be to change the test to something like
[ "A"$option != "A" ]
Other than that, it might just be that you need a space between the ! and the "-n"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 09:50 PM
02-08-2004 09:50 PM
Re: Script error
you should test [ -n "$option" ].
This will result in testing for "" in stead of nothing.
Another hint:
put in the beginning of the script:
set -u # unset variable -> exit.
(This will cause problems in this specific case though).
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 09:53 PM
02-08-2004 09:53 PM
Re: Script error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2004 10:05 PM
02-08-2004 10:05 PM
Re: Script error
[ "A"$option = "A" ]
This works.
Regards,
John.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2004 02:33 AM
02-09-2004 02:33 AM
Re: Script error
[ ! -n $option ]
is really
[ ! -n ]
which will be the case if you trace the execution using set -x. To tell the shell that there really is something to look at (including nothing), use the " characters around $option as in "$option" which now makes a null entry look like this:
[ ! -n "" ]
and that is a valid test condition. Similarly, you could test something like this:
if [ "$option" -ne "" ]
then
...real option was entered
else
...nothing entered
fi
Note that option="" is different than undefined. The default for POSIX shells is typically that an undefined variable looks like a null variable, but this can have grave consequences in sysadmin scripts (like when a spelling error causes the removal of an entire directory). Most script writers will put: set -u at the start of every script and thus, any spelling errors will stop the script when an undefined variable is used.
There is even a way to handle unset variables when set -u is used:
set -u
UNSET=IamNOTset
DT=${DT:-$UNSET}
VUE=${VUE:-$UNSET}
if [ $VUE -ne $UNSET ]
then
...process code for VUE...
fi
The :- construct will leave the variable untouched if it had been previously defined but change it to whatever follows :- if it was never defined. If necessary (such as in profile scripts), return the variable back to it's original state:
[ $VUE = $UNSET ] && unset VUE
The text for UNSET is arbitrary, I just use IamNOTset since it is unlikely to be found in most variables.
Bill Hassell, sysadmin