Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

no habla bash muy bien...



Guys,

Thanks for all the tips re: bash, awk, sed, etc. I didn't respond to 
everyone individually, but I read everyones advice and suggestions and 
took them into consideration.


On Jan 29, 2004, at 3:23 PM, Sean T Langan wrote:
>
> One of my friends is a programmer, and once you guys had thoroughly 
> confused
> me with your shell-scripting trickery I bounced the original
> problem/question over to him for some clarification.  In his response 
> to me
> he states that his solution should work, or he will eat a hat.  I 
> would take
> great pleasure in seeing him eat a hat, so here I submit his solution 
> (with
> his permission) for your collective consideration.

I would love to see him eat his hat as well, but unfortunately for you 
and fortunately for him, I gave up on bash/sed/awk before I got his 
message. BUT, before I did, I got it working. Here is the code I had 
working with bash:

   local FILTER_COMMAND="sed -e s/#.*// ${CONFIG_FILE}"
   local VALUE=`$FILTER_COMMAND | awk -F"=" "/$PARAMETER/ { print "'$2'" 
}" `

Basically, the trick was to multiple strings, closing with a " just 
before the $2, which was wrapped in 's, and then finishing up with a 
"ed string.

Here is your friends solution:

> RESULT=`sed -e s/#.*// $CONFIG_FILE | awk -F= '/'$PARAM'/ { print $2 
> }'`

I tried them both just now to test, and they both work. I have attached 
two files, config and printParam.bsh, that illustrate both my solution 
and your friends. If your curious, just save them to file and run:

#sh printParam.bsh

But....

> The real answer to this is:
> "Write a freaking Perl script to do this, you idiot".
> Having a bash environment variable be set by piping a sed script to an 
> awk
> script is just sooooo eighties...

Your friend is absolutely right. I finally decided (after I got the 
bash/awk/sed bit working) that I should just redo the whole think in 
Perl. One major reason is that I dreaded trying to duplicate the same 
work again using windows batch scripting (we do cross platform 
development, so we need to bootstrap our environment on both platforms, 
and had been using a bat file on Windows and a bash script on Linux).

Also, as annoying as I find Perl, at least its an actual programming 
language, and I was able to hash out the whole script (and toss in some 
new features I needed) fairly quickly. The best part was that it took 
only minor tweeking to get it running on Windows.

I've attached my perl script for comparison as well, the relevant 
reg-exps are in there somewhere.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: config
Type: application/octet-stream
Size: 12 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20040130/ecccb422/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: printParam.bsh
Type: application/octet-stream
Size: 292 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20040130/ecccb422/attachment-0001.obj>
-------------- next part --------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: LaunchEnvironment.pl
Type: application/octet-stream
Size: 5912 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20040130/ecccb422/attachment-0002.obj>
-------------- next part --------------


-- 
Joshua Pollak
Software Engineer
Charles River Analytics
617-491-3474 x586





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org