I want to execute a shell script that require 3 arguments.
The argument number 2 contains a string with space
I want to put all arguments in one variable like this:
Linux:~# kk="\"111\" \"222 222\" \"333\""
Linux:~# echo $kk
"111" "222 222" "333"
Now If I call a function:
func() {
echo ---$1---
echo ---$2---
echo ---$3---
}
with the $kk variable in this way
func $kk
Then it will return
Linux:~# func $kk
---"111"---
---"222---
---222"---
And I was expecting to get this result
---111---
---222 222---
---333---
How to solve this issue without using eval
?
I know that the eval
solve this issue but I do not want to use it (since it takes time if I execute many time a such call).
eval
. See mywiki.wooledge.org/BashFAQ/050 for details. – Runoffeval
-- the potential security impact is a much larger concern. – Subassembly"$@"
, if one doesn't need it and doesn't want to use a function for scoping). – Subassembly"111" "222 222" "333"
is meant to be exactly one argument containing literal quotes, four arguments containing literal quotes but split on whitespace, or three arguments with no quotes -- but imposing parsing rules on expansion would be a rat's nest of security bugs, so Not Doing It is safer, thus shells behave thus. – Subassembly