[plug] How to check for an empty string in a bash script.
Leon Brooks
leonb at bounce.networx.net.au
Wed Dec 15 11:32:10 WST 1999
"Anthony J. Breeds-Taurima" wrote:
> On Wed, 15 Dec 1999, Buddrige, David wrote:
> > 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
> if [ -n "$THE_PATH" ] ; then
> echo the path contains data
> fi
>
> if [ -z "$THE_PATH" ] ; then
> echo the path is empty
> fi
Or the traditional and more portable if much uglier:
if [ X$THE_PATH = X ]; then
echo 'The path is empty. Hammer to the metal! Let's moooove!'
fi
---
Confidence is the feeling you have before you understand the situation.
If at first you don't succeed, try a shorter bungee. When in trouble,
when in doubt, run in circles, scream and shout. The two great secrets
of success are: don't tell anyone everything that you know.
More information about the plug
mailing list