- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help shell script if..else fi
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
Discussions
Discussions
Forums
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
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
тАО05-12-2005 07:17 AM
тАО05-12-2005 07:17 AM
help shell script if..else fi
when make set -x obtaing a error line 20
'[' ']'
./filtra.ori: : No such file or directory
echo "$TEST is null"
.....
.....
if [ $? -ne 0 ]
then
echo "Hello"
TEST=`grep ou file`
if [ $TEST <> "" ] #line 20
echo "$TEST is null"
else
echo "action.."
fi
else
echo "hello bad"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2005 07:22 AM
тАО05-12-2005 07:22 AM
Re: help shell script if..else fi
if [ $TEST <> "" ]
supposed to do? That is not a valid comparison. Do want the 'then' action to when TEST is null or when TEST is NOT NULL?
You are also missing a 'then' after that if statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2005 07:34 AM
тАО05-12-2005 07:34 AM
Re: help shell script if..else fi
then
else
fi
BTW, what is the <> you have? Is this "not equal"? I am familar with the '!=' and the '-ne'. Haven't seen the '<>' but this could be lack of exposure on my part...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2005 07:46 AM
тАО05-12-2005 07:46 AM
Re: help shell script if..else fi
Also make sure that the you have spaces next to the [ and ] .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2005 11:50 AM
тАО05-12-2005 11:50 AM
Re: help shell script if..else fi
if [ ! -z "$TEST" ]
then
See 'man test' for different options to single-[]'s, as against the possible shell internal ([[ ]], as in posix and korn shells) evaluation/testing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-12-2005 03:38 PM
тАО05-12-2005 03:38 PM
Re: help shell script if..else fi
if [ <> "" ]
which makes no sense. Enclose $TEST with quotes and the statement will look like this:
if [ "" <> "" ]
But as mentioned, <> is not a valid shell expression. The 3 comparison operators are = < . so to get "not equal", use the ! as negation. So not-equal is: != and your test should be:
if [ "$TEST" != "" ]
or
if [ -z "$TEST" ]
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-13-2005 01:01 AM
тАО05-13-2005 01:01 AM
Re: help shell script if..else fi
Thank, I solved my problem:
...
if [ x$TEST == "" ]
then
echo "$TEST is null"
...
********if is true*************
ouput , set -x
TEST=`grep ou file`
++ TEST=
++ '[' x == x ']'
++ echo ' is null'
is null
*********if is FALSE************
++ TEST=*oufileover.ou
++ '[' 'x*oufileover.ou' == x ']'
++ echo 'action'
action