5 ms·
You can use arrays. $ ls -la "foo bar" -rw------- 1 u0_a298 u0_a298 6 Jan 10 00:22 'foo bar' $ cmd=(cat "foo bar") $ "${cmd[@]}" hello Edi
by mkdirp 5y ago
You can use arrays.
$ ls -la "foo bar"
-rw------- 1 u0_a298 u0_a298 6 Jan 10 00:22 'foo bar'
$ cmd=(cat "foo bar")
$ "${cmd[@]}"
hello
Edit, since someone pointed out you the article is using dash, something I overlooked, you can still avoid eval by using set to overload the script args:
$ set -- cat "foo bar"
$ "$@"
hello
Not sure how this would work if you still need the values of the current args. I don't think there is a way set a variable to be the current "$@" to be used later. However, if you don't need the current args any more, this is a possible solution to avoid eval.