Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Standard shell programming technique' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Standard shell programming technique
Authored by: TrumpetPower! on Mar 30, '05 10:19:49PM

What's happening is that the `echo $TERM_PROGRAM` is displaying "" (an empty string), which test doesn't like on the left hand side of a == operator.

There is a standard technique to avoid just this problem when writing shell scripts. The solution is to prepend a string—usually “X”—to both strings to be tested.

For example:

if [ X"${foo}" == X"bar" ]; then
    echo "foo is bar";
else
    echo "foo is not bar";
fi

That should be portable across pretty much any Bourne-style shell.

Cheers,

b&



[ Reply to This | # ]