bash - shell script grep to grep a string -


the output blank fr below script. missing? trying grep string

#!/bin/ksh     file=$abc_def_app_13.4.5.2     if grep -q abc_def_app $file;  echo "file found" else  echo "file not found" fi 

in bash, use <<< redirection string (a 'here string'):

if grep -q abc_def_app <<< $file 

in other shells, may need use:

if echo $file | grep -q abc_def_app 

i put then on next line; if want then on same line, add ; then after wrote.


note assignment:

file=$abc_def_app_13.4.5.2 

is pretty odd; takes value of environment variable ${abc_def_app_13} , adds .4.5.2 end (it must env var since can see start of script). intended write:

file=abc_def_app_13.4.5.2 

in general, should enclose references variables holding file names in double quotes avoid problems spaces etc in file names. not critical here, practices practices:

if grep -q abc_def_app <<< "$file" if echo "$file" | grep -q abc_def_app 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -