- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- trouble with "||" operand
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
04-17-2008 03:09 AM
04-17-2008 03:09 AM
I cant get my if statement to work and I believe it may be to do with the || in the script:
print "Please enter a hdisk or vpath you would like to check and potentially remove: \c"
while true
do
read ANS
if [[ $ANS != hdisk[0-9]* || $ANS != vpath[0-9]* ]] ; then
print "incorrect selection please enter a valid hdisk or vpath: \c"
else
break
fi
done
what is wrong here?
is it to do with [[
]] - should I be using [
many thanks
Chris.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 03:15 AM
04-17-2008 03:15 AM
Re: trouble with "||" operand
wouldn't it be
if [[ $ANS != hdisk[0-9]* ] || [ $ANS != vpath[0-9]* ]]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 03:27 AM
04-17-2008 03:27 AM
Re: trouble with "||" operand
Please enter a hdisk or vpath you would like to check and potentially remove: ./check_disk.ksh[5]: 0403-057 Syntax error at line 12 : `]' is not expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 03:40 AM
04-17-2008 03:40 AM
Re: trouble with "||" operand
Regards,
Piyush Mathiya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:00 AM
04-17-2008 04:00 AM
Solutionif [[ $ANS != hdisk[0-9]* && $ANS != vpath[0-9]* ]]; then
Yours will always be true.
You may want to reverse your condition so it is more obvious:
if [[ $ANS = hdisk[0-9]* || $ANS = vpath[0-9]* ]] ; then
break
fi
Note your pattern matching will match hdisk, followed by 0 .. 9, followed by anything.
>Piyush: you have to use -a (And) or -o (OR) operator instead of "||"
No, [[ ]] supports && and ||. [] only supports -a and -o.
- Tags:
- boolean
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:01 AM
04-17-2008 04:01 AM
Re: trouble with "||" operand
try it with quotes:
if [[ "$ANS" != "hdisk[0-9]*" || "$ANS" != "vpath[0-9]*" ]] then
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:03 AM
04-17-2008 04:03 AM
Re: trouble with "||" operand
Only [[ ]] does pattern matching, [ ] does exact match.
>Oviwan: try it with quotes:
if [[ "$ANS" != "hdisk[0-9]*" || "$ANS" != "vpath[0-9]*" ]]
No, that will break pattern matching.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:15 AM
04-17-2008 04:15 AM
Re: trouble with "||" operand
As I already post a solution, you can use the following command.
if [[ $ANS != hdisk[0-9]* -a $ANS != vpath[0-9]* ]] ; then
Regards,
Piyush Mathiya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:21 AM
04-17-2008 04:21 AM
Re: trouble with "||" operand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:23 AM
04-17-2008 04:23 AM
Re: trouble with "||" operand
your pattern hdisk[0-9]* will not work in if condition.
print "Please enter a hdisk or vpath you would like to check and potentially remove: \c"
while true
do
read ANS
a=`echo $ANS|awk '/hdisk[0-9]/ {print $0}'`
b=`echo $ANS|awk '/vpath[0-9]/ {print $0}'`
if [ $a ] || [ $b ] ;
then
print "incorrect selection please enter a valid hdisk or vpath: \c"
else
break
fi
done
thanks & regards
aashique
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:28 AM
04-17-2008 04:28 AM
Re: trouble with "||" operand
Chris is obviously using a real shell and not the scummy C shell.
>Aashique: your pattern hdisk[0-9]* will not work in if condition.
Why not? Pattern matching will work in [[ ]].
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:35 AM
04-17-2008 04:35 AM
Re: trouble with "||" operand
I check this way and its running.
$ more test
ANS=vpath02
a=`echo $ANS|awk '/hdisk[0-9]/ {print $0}'`
b=`echo $ANS|awk '/vpath[0-9]/ {print $0}'`
if [ $a ] || [ $b ]
then
echo " YES"
else
echo "NO"
fi
$ ./test
YES
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:39 AM
04-17-2008 04:39 AM
Re: trouble with "||" operand
Ok thanks all,
I'll give take a look at these suggestions and let you know ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 04:48 AM
04-17-2008 04:48 AM
Re: trouble with "||" operand
#!/bin/ksh
print "Please enter a hdisk or vpath you would like to check and potentially remove: \c"
while true
do
read ANS
if [[ $ANS = hdisk[0-9]* || $ANS = vpath[0-9]* ]] ; then
break
print "incorrect selection please enter a valid hdisk or vpath: \c"
else
print "incorrect selection please enter a valid hdisk or vpath: \c"
fi
done
echo $ANS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 05:01 AM
04-17-2008 05:01 AM
Re: trouble with "||" operand
have a look the following url:
http://www.injunea.demon.co.uk/pages/page205.htm
should look something like:
if [ $ANS != hdisk[0-9]* ] || [ $ANS != vpath[0-9]* ]
then
..
(unfortunately, i do not have any machine at hand to validate this right now!)
The [[ ]] are not properly stated.
hope this helps!
kind regards
yogeeraj
- Tags:
- Bourne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2008 11:31 AM
04-17-2008 11:31 AM
Re: trouble with "||" operand
http://www.injunea.demon.co.uk/pages/page205.htm
This appears to be Borne shell document, not ksh or posix.
http://docs.hp.com/en/B2355-60130/sh-posix.1.html
http://docs.hp.com/en/B2355-60130/ksh.1.html