bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash $@ Parameter Variable Breaking Out of Strings


From: Adam Danischewski
Subject: Re: Bash $@ Parameter Variable Breaking Out of Strings
Date: Tue, 22 Mar 2016 11:13:14 -0400

I hit send by accident, disregard the first part - I had the info page open and didn't realize I had sent the email already, the "$*" is what I should be using.

The second part is still of a mystery, again a quick typo where it states VAR2=2, it should read VAR2=3 to obtain 47.

On Tue, Mar 22, 2016 at 10:47 AM, Adam Danischewski <adam.danischewski@gmail.com> wrote:
I noticed an issue using the parameter built-in variable $@ breaking
out of contained strings when utilized in functions.

For example, consider the following bash script: m.bsh
#!/bin/bash
echo "$#"
while getopts d: OPTION "$@"; do
 case "$OPTION" in
   d)
     echo "the optarg is ${OPTARG##*=}, optind is ${OPTIND}"
     [[ -z "${OPTARG}" ]] && echo "Let's set the null byte as the delim."
    ;;
 esac
done
exit 0


$ alias t1='_() { var=$@; /tmp/m.bsh -d "clarify ${var}"; }; _'
$ t1 hi there
2
the optarg is clarify hi there, optind is 3 
 ### Correctly considers the text as a single string argument
     containing a space.

$ alias t2='_() { /tmp/m.bsh -d "clarify $@"; }; _'
$ t2 hi there
3
the optarg is clarify hi, optind is 3
 ### Incorrectly breaks the argument array variable out as separate
     single string arguments.

I noticed another interesting occurrence as well, I'm not sure if they are related, to variable names:

function update() {
local -i VAR=45
VAR+=-1
VAR+=$1
echo $VAR
}

$ VAR2=2
$ update VAR2
  47

$ VAR=3
$ update VAR
  88 ### !? 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]