grep works as commandine but fails as varible
grep '^Sep 7' /var/log/warn
Works at command line but: teststr='^Sep 7' grep ${teststr} /var/log/warn Fails as it returns all lines which start with Sep. Any ideas? Thanks -jim |
You have to put double quotes around the variable reference to protect the blank space(s):
Code:
grep "${teststr}" /var/log/warn Code:
grep ^Sep 7 /var/log/warn |
That works until it is put in a bash script.
Then it fails to find any entries in the file. Any ideas? Thanks |
Quote:
In the meanwhile you can compare your code with a working example tested with grep-2.5.4 and bash-4.1.7: Code:
#!/bin/bash |
Try adding the full path to the grep command in the script as well.
|
Thanks.
With your help and fixing some typos and other errors, we did get this to work. Code:
#!/bin/bash -jim |
No Problem, Jim. Please mark the thread as solved and feel free to give reputation points to those who you found helpful!
|
All times are GMT -5. The time now is 07:03 AM. |