[TriLUG] String Evaluation

Shawn Taylor shtaylor at gpi.com
Tue Jul 29 13:16:01 EDT 2008


Can someone please explain the difference between these variable usages?

Specifically is it better/more common/more portable to use ${testString}
instead of "$testString" in my scripts?

Example below.

Thanks,

Shawn

<script>

#!/bin/bash

declare testString
testString="This is a test string"

echo $testString
echo "$testString"
echo ${testString}

# THIS IS WHERE THE FUN BEGINS

if [ -n $testString ]; then
	echo "String Not Empty - 1"
fi


if [ -n ${testString} ]; then
	echo "String Not Empty - 2"
fi


if [ -n "$testString" ]; then
	echo "String Not Empty - 3"
fi

</script>






More information about the TriLUG mailing list