|First, generally, $1 is the first command argument of your script. (I say, generally, because the unix set comamnd can change $1, $2, etc. I'll ignore that for the purposes of this discussion). Assume your shell script is called x.ss. Executing:|
$1 will equal the string "-tkdiff". Executing x.ss with no command line arguments, sets $1 to null or undefined.
Consider this line:
if [ x"$1" = x"-tkdiff" ]; then
if $1 equals -tkdiff, the first part of the if statement executes; If $1 is undefined or equals some other value the else executes.
You're probably wondering why the guy did this? Why not just do this:
if [ "$1" = "-tkdiff" ]
echo "command line arg is -tkdiff"
He should have. The "x" really doesn't get you anything. He probably modified a bourne shell null check.
While the korn and bash shells have a string null check (-z), the bourne shell does not. This is one way of checking with the bourne shell whether $1 is null:
if [ x"$1" = x ]; then
echo "command line arg 1 is null"
echo "it exists"
if $1 is null, then x equals x and the first part of the if statement identifies $1 as null.
Let me know if you have any questions.