[plug] How to check for an empty string in a bash script.
John Summerfield
summer at os2.ami.com.au
Thu Dec 16 07:16:12 WST 1999
> Hi all,
>
> I have the following code in a bash script that I am writing...
>
> if [ THE_PATH="" ]; then
> echo "The Path is:" $THE_PATH
> echo "FAIL! FILE DOES NOT EXIST."
> fi
>
> In another part of the script, the variable "THE_PATH" is populated with a
> filename that is the result of a search of the filesystem. If the file was
> not found that value should be empty. However, when I run this code, it is
> printing out the filename for which I searched (indicating that the variable
> "THE_PATH" is NOT empty, yet still it is making into the TRUE part of this
> if statement and subsequently echoing "FAIL! FILE DOES NOT EXIST."
>
> My question: How does one check a variable in a bash script to see if it is
> empty?
help test
if [ -z "$VAR" ] ; then
Note the spaces. bash is VERY touchy.
--
Cheers
John Summerfield
http://os2.ami.com.au/os2/ for OS/2 support.
Configuration, networking, combined IBM ftpsites index.
More information about the plug
mailing list