BASH weird acting: unquoted parameter accepted as quoted one !

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH weird acting: unquoted parameter accepted as quoted one !
# 1  
Old 08-02-2011
BASH weird acting: unquoted parameter accepted as quoted one !

In one session I have strange behavior of the bash-shell:
SDX-Q> echo ">$ss<"  #this is just to present the $ss var:
>   lll    kkk  <
SDX-Q>  # more obviose:
SDX-Q> od -cb <<<"$ss"
0000000               l   l   l                   k   k   k          \n
         040 040 040 154 154 154 040 040 040 040 153 153 153 040 040 012
SDX-Q> # now the strange acting:
SDX-Q> echo $ss
   lll    kkk
SDX-Q> # but, it should be : "lll kkk"; To show all spaces printed out:
SDX-Q> echo $ss | tr ' ' '.'
SDX-Q> # something strange with arrays:
SDX-Q> set -- "  aaa  " bbb     cccc   last   $ss
SDX-Q> echo "$*"
  aaa  ~bbb~cccc~last~   lll    kkk
SDX-Q> # The '~' are not understandable there and, again, 
SDX-Q> # the $ss should not be accepted with spaces!
SDX-Q> echo $*
  aaa   bbb cccc last    lll    kkk
SDX-Q> # that is fine, besides, again, the variable $ss 
SDX-Q> printf "%s\n" "$*"
  aaa  ~bbb~cccc~last~   lll    kkk
SDX-Q> # The same  for array ...
SDX-Q> printf "%s\n" $*
   lll    kkk
SDX-Q> # that is fine, besides the $ss

So, the main problem is getting a variable as one unit, while it is frequently expected interpolation to pieces.

Could anyone explain what is happened in that session?
Is it possible to make shell acting that way explicitely and, of couse, restore to regular processing way?

Other sessions behaive as expected.
If I start a 'bash' in that one, everything is as expected again.
That way it is not related to the connecting soft: I use PuTTY, btw.
And my OS is SUN Solaris, if that make any difference.

(If anything would be need to be tested, let me know: I keep the session opened.)
# 2  
Old 08-02-2011
Only two things I can suggest:
1. IFS variable was changed somehow.
2. It's zsh shell.
This User Gave Thanks to yazu For This Post:
# 3  
Old 08-02-2011
Originally Posted by yazu
Only two things I can suggest:
1. IFS variable was changed somehow.
- damn!!, you right!!

It is: the $IFS='~'
That why it separate the array's element with ~

You genius!

Last edited by pludi; 08-02-2011 at 04:46 PM..
# 4  
Old 08-02-2011
"$@" would ignore that anyway if you need to use IFS for something else.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Parameter Expansion

I have made the following examples that print various parameter expansions text: iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018.sac (text%.*): iv-hhz-sac/hpac/hhz.d/iv.hpac..hhz.d.2016.250.070018 (text%%.*): iv-hhz-sac/hpac/hhz (text#*.): d/iv.hpac..hhz.d.2016.250.070018.sac... (2 Replies)
Discussion started by: kristinu
2 Replies

2. Shell Programming and Scripting

Bash script acting funny when run from Crontab

Hello, first time here. I have a script that seems to ignore the if statement when run from the cron. I am using Ubuntu 12.10 #!/bin/bash DOWN=/usr/sbin/dcon UP="pon dsl-provider" LOG=/var/log/dsl-reconnect.log RECV=`ifconfig 2>&1|grep ppp0|cut -d , -f 5|cut -d " " -f 1` if ] then... (1 Reply)
Discussion started by: mkoster
1 Replies

3. Shell Programming and Scripting

Take quoted output from one script as quoted input for another script

Hi, I have a script which produces the following output (as an example): "abc def" "ghi jkl" This output should be handled from script as input and the quotes should be treated as variable delimiters but not as regular characters. (processing positional... (2 Replies)
Discussion started by: stresing
2 Replies

4. Shell Programming and Scripting

In bash getting weird output from function ?

My script- result="" times() { echo "inside the times function" result=8 echo "Inside function $result" return $result } result=$(times) echo "the value is "$? echo "the value of result $result" when I run I get this, why the value still remain 0. $ ./func the value is 0 the value... (5 Replies)
Discussion started by: boy18nj
5 Replies

5. Shell Programming and Scripting

bash: combine arrays with weird substitution/references

Hi all. I'm trying to finish a bash script with the following elements: ARRAY="blah $ITEM blah blah" ARRAY="blah blah $ITEM blah bluh" #ARRAY="...." # ...the ARRAY elements represent a variable but defined # syntax and they're all hard-coded in the script. #(...) ITEMS='1.0 2.3... (2 Replies)
Discussion started by: yomaya
2 Replies

6. UNIX for Dummies Questions & Answers

grep hangs for unquoted string

Guys, This weird problem popped out last week when I grepped for a certain unquoted string in a file, instead of listing all the matches, it just hangs. Here is the exact grep command: $> grep odt01758 LogFile But when I quote the grep pattern, it successfully prints out the matches: $>... (2 Replies)
Discussion started by: rainier
2 Replies

7. Shell Programming and Scripting

script acting weird..

Hi Guys, I have this script which is being called from another script, sh +x SCRIPTNAME. Now this script is failing saying the source file is missing. But i was able to see the source file was present. It was renamed and but somehow the source file is removed. There is no remove command in the... (1 Reply)
Discussion started by: mac4rfree
1 Replies

8. Shell Programming and Scripting

bash-function with array acting bizarre, bug?

Hello, basically what this script is supposed to do is showing a list of hosts that is given a number, that you will be able to choose from a list. A check is made to verify that the chosen number is within the array and this is where things go bad and I don't know why, bizarre. I've spent... (5 Replies)
Discussion started by: gand
5 Replies

9. Shell Programming and Scripting

Why for loop is acting weird

Hey i have a small script in which i check if a file with that pattern exists or not. If present then i go ahead with further processing. In the present situation i have only one file with that name and for loop is reading twice. Here is the script. And the output of debug mode. Please help.... (5 Replies)
Discussion started by: dsravan
5 Replies

10. UNIX for Dummies Questions & Answers

How to get rid of all the weird characters and color on bash shell

Does anyone of you know how to turn off color and weird characters on bash shell when using the command "script"? Everytime users on my server used that command to record their script, they either couldn't print it because lp kept giving the "unknown format character" messages or the print paper... (1 Reply)
Discussion started by: Micz
1 Replies
Login or Register to Ask a Question

Featured Tech Videos