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

Re: scripting - how to handle blanks



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/24/08 10:52, michael wrote:
> Folks, I wish to do something like the following in a bash script but
> can't work out the correct incantation of escape chars etc so any advice
> welcome! ie what is it I need to do for env var STRING and the grep
> command so that grep -e $STRING handles the space in STRING correctly.
> 
> Ta, Michael
> 
> 
> #!/bin/bash -x
> 
> ### script to check when STRING appears in FILE
> 
> if [[ $# -eq 0 ]]; then
> 	    STRING=After\ NEXTIME
> 	    FILE=UK108_N2O5aeroHet_varGamma-hybridCMU_INI.log
> elif [[ $# -eq 2 ]]; then
> 	    STRING=$1
> 	    STRING=$2
> else
>     echo Usage\: $0 [string file]
>     echo To loop until \$string found in \$file
>     exit
> fi
> echo Looping until 
> echo "  '${STRING}'"
> echo found in $FILE
> 
> while [[ `grep -e ${STRING} ${FILE} |wc -l` -lt 1 ]];do 
>     echo nope
>     sleep 60
> done

What happens when you do this?
$ grep -e "After NEXTIME" \
                       UK108_N2O5aeroHet_varGamma-hybridCMU_INI.log

- --
Ron Johnson, Jr.
Jefferson LA  USA

We want... a Shrubbery!!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIELEyS9HxQb37XmcRAildAJ9v8S9UaFRQBc9vm0YPsfmPbNJlEQCg3ope
roY1MD6LY97JVHTj6CDBwr4=
=/9VP
-----END PGP SIGNATURE-----


Reply to: