Sponsored Content
Top Forums Shell Programming and Scripting BASH weird acting: unquoted parameter accepted as quoted one ! Post 302543905 by alex_5161 on Tuesday 2nd of August 2011 11:17:36 AM
Old 08-02-2011
BASH weird acting: unquoted parameter accepted as quoted one !

In one session I have strange behavior of the bash-shell:
Code:
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
0000020
SDX-Q> 
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 ' ' '.'
...lll....kkk..
SDX-Q> 
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> 
SDX-Q> printf "%s\n" "$*"
  aaa  ~bbb~cccc~last~   lll    kkk
SDX-Q> # The same  for array ...
SDX-Q> 
SDX-Q> printf "%s\n" $*
  aaa
bbb
cccc
last
   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.
BASH_VERSION='3.00.16(1)-release'

(If anything would be need to be tested, let me know: I keep the session opened.)
Thanks!
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. Shell Programming and Scripting

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

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

9. 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

10. 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
SYSTEM(3)						     Linux Programmer's Manual							 SYSTEM(3)

NAME
system - execute a shell command SYNOPSIS
#include <stdlib.h> int system(const char *string); DESCRIPTION
system() executes a command specified in string by calling /bin/sh -c string, and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT will be ignored. RETURN VALUE
The value returned is -1 on error (e.g. fork failed), and the return status of the command otherwise. This latter return status is in the format specified in wait(2). Thus, the exit code of the command will be WEXITSTATUS(status). In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127). If the value of string is NULL, system() returns nonzero if the shell is available, and zero if not. system() does not affect the wait status of any other children. CONFORMING TO
ANSI C, POSIX.2, BSD 4.3 NOTES
As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop uninterruptable, unless they take care themselves to check the exit status of the child. E.g. while(something) { int ret = system("foo"); if (WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT)) break; } Do not use system() from a program with suid or sgid privileges, because strange values for some environment variables might be used to subvert system integrity. Use the exec(3) family of functions instead, but not execlp(3) or execvp(3). system() will not, in fact, work properly from programs with suid or sgid privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup. (Debian uses a modified bash which does not do this when invoked as sh.) The check for the availability of /bin/sh is not actually performed; it is always assumed to be available. ISO C specifies the check, but POSIX.2 specifies that the return shall always be non-zero, since a system without the shell is not conforming, and it is this that is implemented. It is possible for the shell command to return 127, so that code is not a sure indication that the execve() call failed. SEE ALSO
sh(1), signal(2), wait(2), exec(3) 2001-09-23 SYSTEM(3)
All times are GMT -4. The time now is 06:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy