[TriLUG] bash question
Andrew Ball
anball at gmail.com
Wed Oct 17 12:27:31 EDT 2007
Would something like the following do ?
adball at adball-cs:~$ cmd=""
adball at adball-cs:~$ for e in $exclude
> do
> cmd="$cmd | grep -v $e"
> echo "e: [$e] cmd: [$cmd]"
>
> done
e: [one] cmd: [ | grep -v one]
e: [two] cmd: [ | grep -v one | grep -v two]
e: [three] cmd: [ | grep -v one | grep -v two | grep -v three]
adball at adball-cs:~$ echo $exclude
one two three
adball at adball-cs:~$
On 10/17/07, Joseph Mack NA3T <jmack at wm7d.net> wrote:
>
> 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!
> --
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
>
--
=======================
Andrew D. Ball
勃安足
http://wwwx.cs.unc.edu/~adball/blog/
http://wwwx.cs.unc.edu/~adball/nec_new_voices/
http://filebox.vt.edu/~anball1/
More information about the TriLUG
mailing list