- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- script help
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-02-2002 05:44 AM
04-02-2002 05:44 AM
filecheck=`find . -name "test*.txt"`
if [ $filecheck -eq 0 ]
then
exit
fi
What I am trying to get is if $filechekc is empty then script exit else it continue, but i am getting the following error
./test[4]: test: argument expected
Can someone tell me what i'm doing wrong
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 05:54 AM
04-02-2002 05:54 AM
Re: script help
if [ $filecheck -eq 0 ]
then
exit
fi
If find does not find anything $filecheck will remaing empty so ... two ways:
if [ "$filecheck" -ne "" ] ...
or better
if [ -n "$filecheck" ]....
See man test.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 05:55 AM
04-02-2002 05:55 AM
Re: script help
if [ $filecheck = "" ]
...
which test for empty strings. The one that you use test for numbers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:05 AM
04-02-2002 06:05 AM
Re: script help
Another way:-
--------------------------------
cd
counter=`ll -R | grep test.file | wc -l`
if [[ $counter = 0 ]]
then
exit
fi
-----------------------------------
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:05 AM
04-02-2002 06:05 AM
Re: script help
Another option is to add a line count:
filecheck=`find . -name "test*.txt" | wc -l`
This way you don't have to change your if statement.
HtH,
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:06 AM
04-02-2002 06:06 AM
Re: script help
The problem you are seeing is that you are comparing a null value with zero which is not possible.
A better way to go about it is doing the following.
if [ $filecheck ]
then
echo "a value exists"
else
echo "nothing"
fi
This way if $filecheck is empty it is false if some value is moved to $filecheck it is always true.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:08 AM
04-02-2002 06:08 AM
Re: script help
Also use the "=" instead of "-eq". Scripts act a little funny with the alpha characters instead of the symbols when using numbers.
Hope this helps...
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:09 AM
04-02-2002 06:09 AM
Re: script help
It doesn't work because you're trying to compare a string with a number (and probably an empty string by the look of the error message).
So I suggest that you add:
| wc -w
To the find command, so it spits out the number of ocurrences found (as it is now, it will only collect the files found).
Afterwards, you can compare numbers to numbers.
Just in case you get nothing from the variable, you should also prefix the $filecheck with a zero, so it has always a value:
if [ 0$filecheck -eq 0 ]
Good luck!
Rumagoso
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:18 AM
04-02-2002 06:18 AM
Re: script help
try this
if [ $? -eq 0 ]
then
else
do this
fi
regds
ravi