can i grep a variable
say i have a variable var=`hostname` and I want to make an if statement like
if grep "esp-ueh" $var;then......
how can i do this
I dont want to store this variable in a file and the grep it because my script will be used at the same time on multiple stations and then that file will keep getting overwritten.
var=`hostname`
if [[ `grep -c "esp-ueh" $var ` > 0 ]]; then
echo "exits"
else
echo "does not exists"
fi
cheers,
Devaraj Takhellambam
you can do that...var=$(...your command...) | grep "esp-ueh"if you want testif [ var="esp-ueh" ] then;...
protocomm does the command have to be in `command` for it to work coz when i echo $var it is empty
devtak the code doent seem to work.it always prints "does not exists"
devtak this is the error that i get
grep: esp-ueh32: No such file or directory
does not exist
set a variable
> myvar=alpha123
an exact way to show whats in a variable
> echo "${myvar}"
alpha123
show that ASCII values - each of those numbers is the ASCII representation of the characters. 97 is an 'a', 108 is 'l', and so on. the final 10 is code for a LF (line feed) terminator.
> echo "${myvar}" | od -An -t dC -w10
97 108 112 104 97 49 50 51 10
======================
The marked line can be changed to
if [[ `echo $var | grep -c "esp-ueh" ` > 0 ]];
does anyone have any more suggestions coz both of them dont seem to work
it works now thanks