Results 1 to 7 of 7
I have a following shell script on Linux 64bit machine.
Code:
If [ `uname -a | grep 64` ]
then
echo 64bit
fi
The above script doesn't work properly. Why?
...
- 06-23-2008 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
simple grep in a shell script
I have a following shell script on Linux 64bit machine.
The above script doesn't work properly. Why?Code:If [ `uname -a | grep 64` ] then echo 64bit fi
Also, the following script works fine. What's the difference?
Code:if [ `uname | grep Linux` ] then echo Linux fi
- 06-23-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 06-23-2008 #3Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
Sorry, that was a typo while writing here.. It is 'if'
- 06-23-2008 #4
post the error you get when you run the script
Linux and me it's a love story
- 06-23-2008 #5Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
The key is in the output.
This:
produces an output which contains spaces, so, if will complain that there are too many arguments. Quoting when working with strings is a good thing to do.Code:uname -a | grep 64
On the contrary:
This other command produces a single word as output. So, it will work even if you don't quote it correctly. In any case, it wouldn't hurt either to quote it. So, let's modify the code this way:Code:uname | grep Linux
However, I think that you should be parsing "uname -m" instead. There are lots of ways that a 64 could appear even if you are not using a 64 bits kernel so "uname -m" might be more accurate. It should say "x86_64".Code:If [ "`uname -a | grep 64`" ] then echo 64bit fi
- 06-23-2008 #6Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Please, delete this post, I posted the same thing twice by accident. Sorry.
- 06-23-2008 #7Just Joined!
- Join Date
- Apr 2007
- Posts
- 59
Great!
Thanks, This is the reply I was expecting..


Reply With Quote