On Wed, Jun 16, 2010 at 1:39 PM, David C. Rankin
Guys (DNH),
I'm having trouble building a command line/string containing pipes and then getting it to execute all at once. This is in the lynxdump script I started:
http://www.3111skyline.com/dl/dev/scr/net/lynxdump.sh
I have created a god-awful nested 'if' jungle in the getdump() function that decides what to do based on command line flag settings. What I want to do is be able to piece together a command line that will ultimately look similar to this depending on the options entered on the command line:
lynx -dump "$url" | grep -e '^.*rpm$' | grep -v 'debugsource' | grep -v 'debuginfo' | grep http | sed -e 's/^.*\shttp/http/' >> $ofile
Basically what I want to do is respond to the following command line options and add the corresponding statement if the option is given:
-r|--rpm grep -e '^.*rpm$' --nodebug grep -v 'debugsource' | grep -v 'debuginfo'
I have tried replacing getdump() by simply adding the pieces like this:
[[ $flagDir -eq 1 ]] && dirSTR="" || dirSTR=" -e '/\/$/d'" [[ $flagRPM -eq 1 ]] && rpmSTR="| grep -e '^.*rpm$'" || rpmSTR="" [[ $noDebug -eq 1 ]] && debugSTR=" | grep -v 'debugsource' | grep -v 'debuginfo' " || \ debugSTR=""
dumpSTR="lynx -dump $url ${rpmSTR}${debugSTR}| grep http | sed -e 's/^.*\shttp/http/'${dirSTR}"
Which gives the perfectly correct command line (rpm and nodebug options):
lynx -dump http://madwifi-project.org/suse/11.0/x86_64 | grep -e '^.*rpm$' | grep -v 'debugsource' | grep -v 'debuginfo' | grep http | sed -e 's/^.*\shttp/http/' -e '/\/$/d'
But when attempting to execute 'dumpSTR' within the script, I end up with an invalid option error from lynx:
lynx: Invalid Option: -e
Basically, lynx is considering everything in the string as options to lynx instead of recognizing the pipe. I have checked all lynx options hoping for a '--' option to say end of options, but no joy. Is there a trick that will work here. I'm sure there is, but I just don't understand it yet. What say the gurus?
As last resort, I know I can apply the filters successively to the result of lynx -dump ... by making separate call for each piece, but I wanted to do it all in the single command line like I can just enter on the command line. Is this a stumbling block withing bash?
Thanks for any help :)
-- David C. Rankin, J.D.,P.E.
David, I would think you could use a subshell to do it, but for some reason I can't get even the simple command below to work the way I expect: sh -c "ls -l | awk '{ print $2 }' " But, maybe it will prod your thoughts in a good direction. Greg -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org