Correct quoting in evalShould variables be quoted when executed?In a Bash Script how does the continue command work with embedded loops?Why does sendmail work differently in different shells?How can I have more than one possibility in a script's shebang line?What is wrong with my init.d script [Segmentation fault]How do I check for the existence of a process without a failed exit code being returned?Preform operation in bash only if a variable is less than a second variableparallel processing reading from a file in a loopBash interactive - entire script writing to historyCron jobs monitoring using exit codeParallel ssh commands forking in background but keeping ssh open
Why does string strummed with finger sound different from the one strummed with pick?
What do astronauts do with their trash on the ISS?
Why didn't Daenerys' advisers suggest assassinating Cersei?
Cycling to work - 30mile return
What dog breeds survive the apocalypse for generations?
Deleting the same lines from a list
Have there been any examples of re-usable rockets in the past?
A latin word for "area of interest"
"Counterexample" for the Inverse function theorem
Do high-wing aircraft represent more difficult engineering challenges than low-wing aircraft?
Why aren't satellites disintegrated even though they orbit earth within their Roche Limits?
Why are lawsuits between the President and Congress not automatically sent to the Supreme Court
Why would you put your input amplifier in front of your filtering for and ECG signal?
Why does Taylor’s series “work”?
How to know the path of a particular software?
FIFO data structure in pure C
How can we delete item permanently without storing in Recycle Bin?
Why does the U.S military use mercenaries?
Would life always name the light from their sun "white"
AD: OU for system administrator accounts
Why is Drogon so much better in battle than Rhaegal and Viserion?
What formula to chose a nonlinear formula?
Iterate lines of string variable in bash
301 Redirects what does ([a-z]+)-(.*) and ([0-9]+)-(.*) mean
Correct quoting in eval
Should variables be quoted when executed?In a Bash Script how does the continue command work with embedded loops?Why does sendmail work differently in different shells?How can I have more than one possibility in a script's shebang line?What is wrong with my init.d script [Segmentation fault]How do I check for the existence of a process without a failed exit code being returned?Preform operation in bash only if a variable is less than a second variableparallel processing reading from a file in a loopBash interactive - entire script writing to historyCron jobs monitoring using exit codeParallel ssh commands forking in background but keeping ssh open
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a script, that does nothing useful but execute the positional arguments. (I'm aware of the security risks, and the script does not make anything useful because it's a minimal working example.)
$ cat script
> #!/usr/bin/env bash
>
> eval "$*"
$ cat "docu ment"
> Lorem ipsum dolor sit amet
What I would like to do is call the script with ./script cat "docu ment"
, or ./script cat docu ment
, but the quotes or the escape character vanishes and the script will try cat docu ment
, which doesn't work. How would I fix the quoting in such a case?
EDIT: What I really want to do, is invoke a command as many times until it returns a successful exit code, or it tried n times. My script looks like this:
#!/usr/bin/env bash
# Try command several times, until it reports success (exit code 0)
# or I give up (tried n times)
tryMax=10
try=1
# Do until loop in bash
while
eval "$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do (( try++ ))
done
if [[ "$exitcode" -ne 0 ]]; then
echo -n "I tried hard, but did not manage to make this work. The exit code "
echo "of the last iteration of this command was: $exitcode."
exit "$exitcode"
fi
bash shell-script
add a comment |
I have a script, that does nothing useful but execute the positional arguments. (I'm aware of the security risks, and the script does not make anything useful because it's a minimal working example.)
$ cat script
> #!/usr/bin/env bash
>
> eval "$*"
$ cat "docu ment"
> Lorem ipsum dolor sit amet
What I would like to do is call the script with ./script cat "docu ment"
, or ./script cat docu ment
, but the quotes or the escape character vanishes and the script will try cat docu ment
, which doesn't work. How would I fix the quoting in such a case?
EDIT: What I really want to do, is invoke a command as many times until it returns a successful exit code, or it tried n times. My script looks like this:
#!/usr/bin/env bash
# Try command several times, until it reports success (exit code 0)
# or I give up (tried n times)
tryMax=10
try=1
# Do until loop in bash
while
eval "$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do (( try++ ))
done
if [[ "$exitcode" -ne 0 ]]; then
echo -n "I tried hard, but did not manage to make this work. The exit code "
echo "of the last iteration of this command was: $exitcode."
exit "$exitcode"
fi
bash shell-script
1
./script cat ""docu ment""
will work in this case, but are you really sure that's what you want to do? It's really not viable to pass evaluable scripts in that way, by hand anyway."$@"
would do the same for your toy example - what is your real use case? What sort of commands do you expect to be provided?
– Michael Homer
May 5 at 8:29
Use@
instead of*
. But better still, don't useeval
. It's far more likely there's a safer way of doing whatever it is you're trying to do. Show us that, and you'll get a safe alternative.
– roaima
May 5 at 8:29
You are right. Maybe it's a XY problem. I edited the question, showing what I really want to do.
– pfnuesel
May 5 at 8:35
See also: unix.stackexchange.com/questions/251103/…
– muru
May 5 at 8:37
Unless your command has a shell construct, like pipes or variable assignments, you don't need eval
– muru
May 5 at 8:38
add a comment |
I have a script, that does nothing useful but execute the positional arguments. (I'm aware of the security risks, and the script does not make anything useful because it's a minimal working example.)
$ cat script
> #!/usr/bin/env bash
>
> eval "$*"
$ cat "docu ment"
> Lorem ipsum dolor sit amet
What I would like to do is call the script with ./script cat "docu ment"
, or ./script cat docu ment
, but the quotes or the escape character vanishes and the script will try cat docu ment
, which doesn't work. How would I fix the quoting in such a case?
EDIT: What I really want to do, is invoke a command as many times until it returns a successful exit code, or it tried n times. My script looks like this:
#!/usr/bin/env bash
# Try command several times, until it reports success (exit code 0)
# or I give up (tried n times)
tryMax=10
try=1
# Do until loop in bash
while
eval "$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do (( try++ ))
done
if [[ "$exitcode" -ne 0 ]]; then
echo -n "I tried hard, but did not manage to make this work. The exit code "
echo "of the last iteration of this command was: $exitcode."
exit "$exitcode"
fi
bash shell-script
I have a script, that does nothing useful but execute the positional arguments. (I'm aware of the security risks, and the script does not make anything useful because it's a minimal working example.)
$ cat script
> #!/usr/bin/env bash
>
> eval "$*"
$ cat "docu ment"
> Lorem ipsum dolor sit amet
What I would like to do is call the script with ./script cat "docu ment"
, or ./script cat docu ment
, but the quotes or the escape character vanishes and the script will try cat docu ment
, which doesn't work. How would I fix the quoting in such a case?
EDIT: What I really want to do, is invoke a command as many times until it returns a successful exit code, or it tried n times. My script looks like this:
#!/usr/bin/env bash
# Try command several times, until it reports success (exit code 0)
# or I give up (tried n times)
tryMax=10
try=1
# Do until loop in bash
while
eval "$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do (( try++ ))
done
if [[ "$exitcode" -ne 0 ]]; then
echo -n "I tried hard, but did not manage to make this work. The exit code "
echo "of the last iteration of this command was: $exitcode."
exit "$exitcode"
fi
bash shell-script
bash shell-script
edited May 5 at 8:34
pfnuesel
asked May 5 at 8:22
pfnueselpfnuesel
2,82642342
2,82642342
1
./script cat ""docu ment""
will work in this case, but are you really sure that's what you want to do? It's really not viable to pass evaluable scripts in that way, by hand anyway."$@"
would do the same for your toy example - what is your real use case? What sort of commands do you expect to be provided?
– Michael Homer
May 5 at 8:29
Use@
instead of*
. But better still, don't useeval
. It's far more likely there's a safer way of doing whatever it is you're trying to do. Show us that, and you'll get a safe alternative.
– roaima
May 5 at 8:29
You are right. Maybe it's a XY problem. I edited the question, showing what I really want to do.
– pfnuesel
May 5 at 8:35
See also: unix.stackexchange.com/questions/251103/…
– muru
May 5 at 8:37
Unless your command has a shell construct, like pipes or variable assignments, you don't need eval
– muru
May 5 at 8:38
add a comment |
1
./script cat ""docu ment""
will work in this case, but are you really sure that's what you want to do? It's really not viable to pass evaluable scripts in that way, by hand anyway."$@"
would do the same for your toy example - what is your real use case? What sort of commands do you expect to be provided?
– Michael Homer
May 5 at 8:29
Use@
instead of*
. But better still, don't useeval
. It's far more likely there's a safer way of doing whatever it is you're trying to do. Show us that, and you'll get a safe alternative.
– roaima
May 5 at 8:29
You are right. Maybe it's a XY problem. I edited the question, showing what I really want to do.
– pfnuesel
May 5 at 8:35
See also: unix.stackexchange.com/questions/251103/…
– muru
May 5 at 8:37
Unless your command has a shell construct, like pipes or variable assignments, you don't need eval
– muru
May 5 at 8:38
1
1
./script cat ""docu ment""
will work in this case, but are you really sure that's what you want to do? It's really not viable to pass evaluable scripts in that way, by hand anyway. "$@"
would do the same for your toy example - what is your real use case? What sort of commands do you expect to be provided?– Michael Homer
May 5 at 8:29
./script cat ""docu ment""
will work in this case, but are you really sure that's what you want to do? It's really not viable to pass evaluable scripts in that way, by hand anyway. "$@"
would do the same for your toy example - what is your real use case? What sort of commands do you expect to be provided?– Michael Homer
May 5 at 8:29
Use
@
instead of *
. But better still, don't use eval
. It's far more likely there's a safer way of doing whatever it is you're trying to do. Show us that, and you'll get a safe alternative.– roaima
May 5 at 8:29
Use
@
instead of *
. But better still, don't use eval
. It's far more likely there's a safer way of doing whatever it is you're trying to do. Show us that, and you'll get a safe alternative.– roaima
May 5 at 8:29
You are right. Maybe it's a XY problem. I edited the question, showing what I really want to do.
– pfnuesel
May 5 at 8:35
You are right. Maybe it's a XY problem. I edited the question, showing what I really want to do.
– pfnuesel
May 5 at 8:35
See also: unix.stackexchange.com/questions/251103/…
– muru
May 5 at 8:37
See also: unix.stackexchange.com/questions/251103/…
– muru
May 5 at 8:37
Unless your command has a shell construct, like pipes or variable assignments, you don't need eval
– muru
May 5 at 8:38
Unless your command has a shell construct, like pipes or variable assignments, you don't need eval
– muru
May 5 at 8:38
add a comment |
1 Answer
1
active
oldest
votes
You don't need eval
here. You can just use "$@"
:
while
"$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do ...
"$@"
will expand to all the arguments to the script as separate "words" - respecting the original quoting that prevented word splitting - and then leave you with the first argument as the command waiting to run (cat
), and the remaining arguments as arguments to cat
(docu ment
).
Where this won't work:
- If you want the command passed in to use other higher-level shell constructs, like pipes, function definitions, loops, etc. These are all processed before parameter expansion, and won't be attempted again after
"$@"
is expanded. - If the command has its return code negated
! cmd
.!
is also processed at the start of handling a command, before parameter expansion. - If the command is multiple commands
x ; y
or$'xny'
orx $'n' y
, or the same with&&
or||
. All those are just regular arguments. - If your command has variable assignments preceding it like
LD_LIBRARY_PATH=/x foo
. You can put them before the script name, but not the argument command. - If the command has redirections
>foo
,3<bar
in it. These may or may not be able to be affixed to the script, since the script has its own logging output. - If the command has here-documents or here-strings. These will only be readable one time if affixed to the script itself, so depending on exactly when the command fails you might or might not be all right. These would be very difficult to pass in suitably for
eval
anyway. - If the command is a subshell
( ... )
or command group... ;
. These will be treated as commands called(
and{
, not as syntactic constructs. - If the command contains command substitution
$(...)
that needs to be run repeatedly. You can use that (or any other shell construct) to generate the original arguments, but they will all be fixed strings once the script starts running. - If the command has any other element that should be evaluated repeatedly, like
$RANDOM
or an arithmetic expansion$((i++))
. - If the command is
time
. This is a shell reserved word, and not a built-in command, so it is also processed before parameter expansion.
Otherwise, however, you can successfully avoid eval
entirely, and should probably do so. It's very fragile to construct correctly even ignoring any possible security issues.
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f517185%2fcorrect-quoting-in-eval%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You don't need eval
here. You can just use "$@"
:
while
"$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do ...
"$@"
will expand to all the arguments to the script as separate "words" - respecting the original quoting that prevented word splitting - and then leave you with the first argument as the command waiting to run (cat
), and the remaining arguments as arguments to cat
(docu ment
).
Where this won't work:
- If you want the command passed in to use other higher-level shell constructs, like pipes, function definitions, loops, etc. These are all processed before parameter expansion, and won't be attempted again after
"$@"
is expanded. - If the command has its return code negated
! cmd
.!
is also processed at the start of handling a command, before parameter expansion. - If the command is multiple commands
x ; y
or$'xny'
orx $'n' y
, or the same with&&
or||
. All those are just regular arguments. - If your command has variable assignments preceding it like
LD_LIBRARY_PATH=/x foo
. You can put them before the script name, but not the argument command. - If the command has redirections
>foo
,3<bar
in it. These may or may not be able to be affixed to the script, since the script has its own logging output. - If the command has here-documents or here-strings. These will only be readable one time if affixed to the script itself, so depending on exactly when the command fails you might or might not be all right. These would be very difficult to pass in suitably for
eval
anyway. - If the command is a subshell
( ... )
or command group... ;
. These will be treated as commands called(
and{
, not as syntactic constructs. - If the command contains command substitution
$(...)
that needs to be run repeatedly. You can use that (or any other shell construct) to generate the original arguments, but they will all be fixed strings once the script starts running. - If the command has any other element that should be evaluated repeatedly, like
$RANDOM
or an arithmetic expansion$((i++))
. - If the command is
time
. This is a shell reserved word, and not a built-in command, so it is also processed before parameter expansion.
Otherwise, however, you can successfully avoid eval
entirely, and should probably do so. It's very fragile to construct correctly even ignoring any possible security issues.
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
add a comment |
You don't need eval
here. You can just use "$@"
:
while
"$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do ...
"$@"
will expand to all the arguments to the script as separate "words" - respecting the original quoting that prevented word splitting - and then leave you with the first argument as the command waiting to run (cat
), and the remaining arguments as arguments to cat
(docu ment
).
Where this won't work:
- If you want the command passed in to use other higher-level shell constructs, like pipes, function definitions, loops, etc. These are all processed before parameter expansion, and won't be attempted again after
"$@"
is expanded. - If the command has its return code negated
! cmd
.!
is also processed at the start of handling a command, before parameter expansion. - If the command is multiple commands
x ; y
or$'xny'
orx $'n' y
, or the same with&&
or||
. All those are just regular arguments. - If your command has variable assignments preceding it like
LD_LIBRARY_PATH=/x foo
. You can put them before the script name, but not the argument command. - If the command has redirections
>foo
,3<bar
in it. These may or may not be able to be affixed to the script, since the script has its own logging output. - If the command has here-documents or here-strings. These will only be readable one time if affixed to the script itself, so depending on exactly when the command fails you might or might not be all right. These would be very difficult to pass in suitably for
eval
anyway. - If the command is a subshell
( ... )
or command group... ;
. These will be treated as commands called(
and{
, not as syntactic constructs. - If the command contains command substitution
$(...)
that needs to be run repeatedly. You can use that (or any other shell construct) to generate the original arguments, but they will all be fixed strings once the script starts running. - If the command has any other element that should be evaluated repeatedly, like
$RANDOM
or an arithmetic expansion$((i++))
. - If the command is
time
. This is a shell reserved word, and not a built-in command, so it is also processed before parameter expansion.
Otherwise, however, you can successfully avoid eval
entirely, and should probably do so. It's very fragile to construct correctly even ignoring any possible security issues.
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
add a comment |
You don't need eval
here. You can just use "$@"
:
while
"$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do ...
"$@"
will expand to all the arguments to the script as separate "words" - respecting the original quoting that prevented word splitting - and then leave you with the first argument as the command waiting to run (cat
), and the remaining arguments as arguments to cat
(docu ment
).
Where this won't work:
- If you want the command passed in to use other higher-level shell constructs, like pipes, function definitions, loops, etc. These are all processed before parameter expansion, and won't be attempted again after
"$@"
is expanded. - If the command has its return code negated
! cmd
.!
is also processed at the start of handling a command, before parameter expansion. - If the command is multiple commands
x ; y
or$'xny'
orx $'n' y
, or the same with&&
or||
. All those are just regular arguments. - If your command has variable assignments preceding it like
LD_LIBRARY_PATH=/x foo
. You can put them before the script name, but not the argument command. - If the command has redirections
>foo
,3<bar
in it. These may or may not be able to be affixed to the script, since the script has its own logging output. - If the command has here-documents or here-strings. These will only be readable one time if affixed to the script itself, so depending on exactly when the command fails you might or might not be all right. These would be very difficult to pass in suitably for
eval
anyway. - If the command is a subshell
( ... )
or command group... ;
. These will be treated as commands called(
and{
, not as syntactic constructs. - If the command contains command substitution
$(...)
that needs to be run repeatedly. You can use that (or any other shell construct) to generate the original arguments, but they will all be fixed strings once the script starts running. - If the command has any other element that should be evaluated repeatedly, like
$RANDOM
or an arithmetic expansion$((i++))
. - If the command is
time
. This is a shell reserved word, and not a built-in command, so it is also processed before parameter expansion.
Otherwise, however, you can successfully avoid eval
entirely, and should probably do so. It's very fragile to construct correctly even ignoring any possible security issues.
You don't need eval
here. You can just use "$@"
:
while
"$@"
exitcode="$?"
[[ "$exitcode" -ne 0 && "$try" -lt "$tryMax" ]]
do ...
"$@"
will expand to all the arguments to the script as separate "words" - respecting the original quoting that prevented word splitting - and then leave you with the first argument as the command waiting to run (cat
), and the remaining arguments as arguments to cat
(docu ment
).
Where this won't work:
- If you want the command passed in to use other higher-level shell constructs, like pipes, function definitions, loops, etc. These are all processed before parameter expansion, and won't be attempted again after
"$@"
is expanded. - If the command has its return code negated
! cmd
.!
is also processed at the start of handling a command, before parameter expansion. - If the command is multiple commands
x ; y
or$'xny'
orx $'n' y
, or the same with&&
or||
. All those are just regular arguments. - If your command has variable assignments preceding it like
LD_LIBRARY_PATH=/x foo
. You can put them before the script name, but not the argument command. - If the command has redirections
>foo
,3<bar
in it. These may or may not be able to be affixed to the script, since the script has its own logging output. - If the command has here-documents or here-strings. These will only be readable one time if affixed to the script itself, so depending on exactly when the command fails you might or might not be all right. These would be very difficult to pass in suitably for
eval
anyway. - If the command is a subshell
( ... )
or command group... ;
. These will be treated as commands called(
and{
, not as syntactic constructs. - If the command contains command substitution
$(...)
that needs to be run repeatedly. You can use that (or any other shell construct) to generate the original arguments, but they will all be fixed strings once the script starts running. - If the command has any other element that should be evaluated repeatedly, like
$RANDOM
or an arithmetic expansion$((i++))
. - If the command is
time
. This is a shell reserved word, and not a built-in command, so it is also processed before parameter expansion.
Otherwise, however, you can successfully avoid eval
entirely, and should probably do so. It's very fragile to construct correctly even ignoring any possible security issues.
edited May 5 at 9:17
answered May 5 at 8:43
Michael HomerMichael Homer
52.2k9144181
52.2k9144181
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
add a comment |
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
An excellent answer! Thank you very much for taking the time to answer so comprehensively.
– pfnuesel
May 5 at 9:14
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f517185%2fcorrect-quoting-in-eval%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
./script cat ""docu ment""
will work in this case, but are you really sure that's what you want to do? It's really not viable to pass evaluable scripts in that way, by hand anyway."$@"
would do the same for your toy example - what is your real use case? What sort of commands do you expect to be provided?– Michael Homer
May 5 at 8:29
Use
@
instead of*
. But better still, don't useeval
. It's far more likely there's a safer way of doing whatever it is you're trying to do. Show us that, and you'll get a safe alternative.– roaima
May 5 at 8:29
You are right. Maybe it's a XY problem. I edited the question, showing what I really want to do.
– pfnuesel
May 5 at 8:35
See also: unix.stackexchange.com/questions/251103/…
– muru
May 5 at 8:37
Unless your command has a shell construct, like pipes or variable assignments, you don't need eval
– muru
May 5 at 8:38