[TriLUG] bash question

Joseph Mack NA3T jmack at wm7d.net
Wed Oct 17 12:17:51 EDT 2007


I would like to find all the hard disks on a machine
so I'm querying /etc/fstab. I can handle excluding
/proc etc with a series of "grep -v foo" in the line
(see commented grep line in function below, which works 
fine).

I thought it would be slicker to group the strings to be 
excluded as a variable and make up an exclude_string to put 
into the grep command (see exclude_string below). However 
when I execute this version of the command (uncommented grep 
command below) bash sees

grep -v foo '|'

and says

'|' file not found

bash now sees the '|' as a filename and not as a pipe 
symbol.

What am I doing wrong?

Thanks Joe

----------------------------
#find_disks function

find_disks(){

INCLUDE=""
include_string=""
EXCLUDE="proc none devpts"
exclude_string=""

for include in $INCLUDE
do
 	add_string="grep $include | "
 	include_string="$include_string $add_string"
done

for exclude in $EXCLUDE
do
 	add_string="grep -v $exclude | "
 	exclude_string="$exclude_string $add_string"
done


#disks=`grep dev /etc/fstab | grep -v "\#" | grep -v proc | grep -v devpts | awk '{print $1}' | sed -e 's/\/dev\///g' | tr -d '\060-\071' | sort | uniq | xargs`

disks=`grep dev /etc/fstab | grep -v "\#" | $include_string $exclude_string awk '{print $1}' | sed -e 's/\/dev\///g' | tr -d '\060-\071' | sort | uniq | xargs`

} #find_disks

find_disks
---------------------------



-- 
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!



More information about the TriLUG mailing list