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]

GAH! Bash script insanity



On Wednesday 28 January 2004 4:42 pm, Joshua Pollak wrote:
> Ok, I'm going crazy. I don't know how the script-kiddies deal with bash.

Here's how.  You can do the whole thing in bash without sed or awk.

Here's my script testsetparam.sh
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
platform=$1
param=$2
lineprefix="$platform:$param"
IFS='='
while read myvar myvalue ; 
do
  if [ "$myvar" == "$lineprefix" ] ; then
      echo "$myvalue"
      break
  fi
done < infile 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Here's my testfile, which I think matches your specs
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
unix:PARM1=Parm1UNIX
# win32:PARM1=Parm1WINDOWS
# unix:PARM2=Parm2UNIXBad1
unix:PARM2=Parm2UNIX
# unix:PARM2=Parm2UNIXBad2
win32:PARM2=Parm2WINDOWS
unix:PARM3=Parm3UNIX
win32:PARM3=Parm3WINDOWS
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Here's my usage:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
[david at uni /tmp]$ PARM2=OLDVALUE
[david at uni /tmp]$ echo $PARM2
OLDVALUE
[david at uni /tmp]$ PARM2=`./testsetparam.sh  unix PARM2`
[david at uni /tmp]$ echo $PARM2
Parm2UNIX
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


-------------------------------------------------------------------
DDDD   David Kramer                           http://thekramers.net
DK KD  
DKK D  "Democracy is the art and science of running the circus 
DK KD  from the monkey cage."
DDDD                                                 -H. L. Mencken




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