I am interesting in calling some function using dynamically generated arguments in a bash script.
However, if some of the arguments had spaces, it does not seem to work.
Let's have this test script:
#!/bin/bash
# file uu.sh
[[ -z $1 ]] || echo '$1' $1
[[ -z $2 ]] || echo '$2' $2
[[ -z $3 ]] || echo '$3' $3
[[ -z $4 ]] || echo '$4' $4
[[ -z $5 ]] || echo '$5' $5
[[ -z $6 ]] || echo '$6' $6
[[ -z $7 ]] || echo '$7' $7
[[ -z $8 ]] || echo '$8' $8
[[ -z $9 ]] || echo '$9' $9
[[ -z $0 ]] || echo '$0' $0
Any my script:
#!/bin/bash
# file vv.sh
ARR=(-x)
ARR+=($1)
ARR+=("$1")
ARR+=("'$1'")
ARR+=("\"$1\"")
bash uu.sh ${ARR[*]}
echo
bash uu.sh "${ARR[*]}"
When calling bash vv.sh "a b" I get the following result:
$2 -x
$2 a
$3 b
$4 a
$5 b
$6 'a
$7 b'
$8 "a
$9 b"
$0 uu.sh
$1 -x a b a b 'a b' "a b"
$0 uu.sh
I am expecting a way to pass the variables to uu.sh such as the result would be:
$1 -x
$2 a b
$0 uu.sh
(Which I can get directly by calling bash uu.sh -x a\ b, or bash uu.sh -x "a b", or bash uu.sh -x 'a b')
"$1"and not$1. Also you could use"$@"for all args..uu.sh(and, any how, I tested with the quotation marks, and I still see the same problem)