[s] in k-shell variable

In my script, I try to set a variable with a usage message, like this:

usageMsg="Usage: myScript.sh [nested|silent]"

When I echo out that variable, I get this:

Usage: myScript.sh s

after doing a lot of trial and error, it seems like the "s" inside the brackets has some special meaning. If I replace the s characters with anything else, it works fine.

eg:

usageMsg="Usage: myScript.sh [nedted|filent]"

when that is echo'ed out I get:

Usage: myScript.sh [nedted|filent]

Or boiled down further:

pshirl:# variable="[a]"
pshirl:# echo $variable
[a]

pshirl:# variable=""
pshirl:# echo $variable
s

pshirl:# variable="[aaaaa]"
pshirl:# echo $variable
[aaaaa]

pshirl:# variable="[sssss]"
pshirl:# echo $variable
s

What gives ? What is so special about the "s" ?

Try using:

echo "$variable"

Without the double quotes you leave the variable content open to interpretation by the shell.

As to the mystery of "s", I suspect there is a file or directory with the name "s" in your current directory.

In an unquoted situation [nested|silent] get interpreted as 'try to match one of the characters "d","e","i","l',"n","s","t" or "|" ' (shell globbing)

1 Like

100% right ... there was a file "s" in the directory. I've quoted the variable, and now it's working as expected.

THANK YOU! This was driving me crazy!