Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

[s] in k-shell variable

Shell Programming and Scripting


Tags
globbing, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-13-2017
luvnola luvnola is offline
Registered User
 
Join Date: Jul 2017
Last Activity: 13 July 2017, 2:23 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
[s] in k-shell variable

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


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

When I echo out that variable, I get this:
Code:
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:


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

when that is echo'ed out I get:
Code:
Usage: myScript.sh [nedted|filent]


Or boiled down further:


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

pshirl:# variable="[s]"
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" ?

Last edited by Scrutinizer; 07-13-2017 at 02:16 PM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 07-13-2017
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 25 September 2017, 12:06 PM EDT
Location: Amsterdam
Posts: 11,537
Thanks: 500
Thanked 3,337 Times in 2,944 Posts
Try using:

Code:
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)
The Following User Says Thank You to Scrutinizer For This Useful Post:
jim mcnamara (07-13-2017)
Sponsored Links
    #3  
Old Unix and Linux 07-13-2017
luvnola luvnola is offline
Registered User
 
Join Date: Jul 2017
Last Activity: 13 July 2017, 2:23 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Ah, so simple, thank you

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!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[SHELL: /bin/sh] For loop using variable variable names Vryali Shell Programming and Scripting 2 06-06-2012 10:47 AM
Not able to store command inside a shell variable, and run the variable gvinayagam Shell Programming and Scripting 3 11-19-2010 05:59 AM
Shell assign variable to another variable 3junior Shell Programming and Scripting 3 11-18-2010 10:20 PM
assign awk's variable to shell script's variable? tiger2000 Shell Programming and Scripting 4 04-13-2010 03:53 PM
Enviornment Variable in B shell (I call it nested variable) princelinux Shell Programming and Scripting 4 07-02-2008 01:35 AM



All times are GMT -4. The time now is 01:41 AM.