[s] in k-shell variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [s] in k-shell variable
# 1  
Old 07-13-2017
[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 03:16 PM.. Reason: code tags
# 2  
Old 07-13-2017
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)
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 07-13-2017
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies

2. Shell Programming and Scripting

how to assign more than 1 variable value from 1 common shell to many other shell files

i have 1 file say LogDirectory='/var/tmp/logs' DataDirectory='/var/tmp/data' DBUSER='scott' now i want to access these variables in many files where #!/bin/bash ${DBUSER} , ${DataDirectory} are called how do i do that? Video tutorial on how to use code tags in The UNIX and Linux... (2 Replies)
Discussion started by: Gl@)!aTor
2 Replies

3. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

4. Shell Programming and Scripting

C Shell path variable causing very slow shell!?HELP

I am using C Shell MKS Toolkit and I ran into a huge problem when setting up some environment variables.:confused: The csh script that I have as my login script runs fine but very very slow. When I add a directory to my PATH it seems to slow down shell startup and even slow down the commands. ... (0 Replies)
Discussion started by: vas28r13
0 Replies

5. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

6. Shell Programming and Scripting

Shell assign variable to another variable

How can I assign a variable to an variable. IE $car=honda One way I can do it is export $car=honda or let $car=2323 Is there any other ways to preform this task (3 Replies)
Discussion started by: 3junior
3 Replies

7. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

8. Shell Programming and Scripting

Local variable shell/new shell

Hi! I'm trying to figure out how to reuse an "old" variable in a new bourne shell. Am i supposed to use the export function? If i write: NAME="Simon" echo $NAME it returns Simon, but if i start a new shell and write echo $NAME it can't be found of course. How do i solve this? ... (7 Replies)
Discussion started by: bib2006
7 Replies

9. Shell Programming and Scripting

Enviornment Variable in B shell (I call it nested variable)

#!/bin/sh APP_ROOT_MODE1=/opt/app1.0 APP_ROOT_MODE2=/opt/app2.0 APP_ROOT=${APP_ROOT_${APP_MODE}} # enviornment variable APP_MODE will be exported in the terminal where # we run the applciation, its value is string - MODE1 or MODE2 # My intension is: # when export APP_MODE=MODE1... (4 Replies)
Discussion started by: princelinux
4 Replies

10. Shell Programming and Scripting

set variable with another variable? c shell

okay, this shouldn't be difficult but I can't figure it out. How can I set a variable with another variable. I have the following: foreach pe ($dir $sp) set tpe = `echo $pe | grep M` if ($tpe == M) then set ${$pe} = M <--- This doesn't work else endif end In this case what... (2 Replies)
Discussion started by: wxornot
2 Replies
Login or Register to Ask a Question