bash error on eval containing blank space

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this:
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
On test.sh script I want to assign to any variable the relevant value:
#!/bin/bash
eval `echo "$@"`
echo $ftpcmd
But I get a prova: command not found error.
I cannot understand what's wrong on my ftpcmd='CWD debug' parameter neither how I should write it instead.
If I try to replace eval with declare then the $ftpcmd is set only to CWD instead of CWD debug as I'm expecting.
bash shell quoting variable whitespace
add a comment |Â
up vote
1
down vote
favorite
I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this:
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
On test.sh script I want to assign to any variable the relevant value:
#!/bin/bash
eval `echo "$@"`
echo $ftpcmd
But I get a prova: command not found error.
I cannot understand what's wrong on my ftpcmd='CWD debug' parameter neither how I should write it instead.
If I try to replace eval with declare then the $ftpcmd is set only to CWD instead of CWD debug as I'm expecting.
bash shell quoting variable whitespace
2
don't reinvent the wheel. option parsing was done years ago. usegetopts(bash built-in, short single-letter options only) or/usr/bin/getopt(from util-linux, supports both short and --long options)
â cas
Oct 2 '15 at 10:39
1
see: unix.stackexchange.com/questions/62950/â¦
â cas
Oct 2 '15 at 10:44
@cas you're right. As I wrote I've still many things to learn on bash scripting.
â Stefano Radaelli
Oct 2 '15 at 10:57
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this:
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
On test.sh script I want to assign to any variable the relevant value:
#!/bin/bash
eval `echo "$@"`
echo $ftpcmd
But I get a prova: command not found error.
I cannot understand what's wrong on my ftpcmd='CWD debug' parameter neither how I should write it instead.
If I try to replace eval with declare then the $ftpcmd is set only to CWD instead of CWD debug as I'm expecting.
bash shell quoting variable whitespace
I need to triggeer a bash passing parameter with a format [ variable_name="value" ] like this:
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
On test.sh script I want to assign to any variable the relevant value:
#!/bin/bash
eval `echo "$@"`
echo $ftpcmd
But I get a prova: command not found error.
I cannot understand what's wrong on my ftpcmd='CWD debug' parameter neither how I should write it instead.
If I try to replace eval with declare then the $ftpcmd is set only to CWD instead of CWD debug as I'm expecting.
bash shell quoting variable whitespace
bash shell quoting variable whitespace
edited Aug 21 at 3:15
Rui F Ribeiro
36.7k1271116
36.7k1271116
asked Oct 2 '15 at 10:37
Stefano Radaelli
1084
1084
2
don't reinvent the wheel. option parsing was done years ago. usegetopts(bash built-in, short single-letter options only) or/usr/bin/getopt(from util-linux, supports both short and --long options)
â cas
Oct 2 '15 at 10:39
1
see: unix.stackexchange.com/questions/62950/â¦
â cas
Oct 2 '15 at 10:44
@cas you're right. As I wrote I've still many things to learn on bash scripting.
â Stefano Radaelli
Oct 2 '15 at 10:57
add a comment |Â
2
don't reinvent the wheel. option parsing was done years ago. usegetopts(bash built-in, short single-letter options only) or/usr/bin/getopt(from util-linux, supports both short and --long options)
â cas
Oct 2 '15 at 10:39
1
see: unix.stackexchange.com/questions/62950/â¦
â cas
Oct 2 '15 at 10:44
@cas you're right. As I wrote I've still many things to learn on bash scripting.
â Stefano Radaelli
Oct 2 '15 at 10:57
2
2
don't reinvent the wheel. option parsing was done years ago. use
getopts (bash built-in, short single-letter options only) or /usr/bin/getopt (from util-linux, supports both short and --long options)â cas
Oct 2 '15 at 10:39
don't reinvent the wheel. option parsing was done years ago. use
getopts (bash built-in, short single-letter options only) or /usr/bin/getopt (from util-linux, supports both short and --long options)â cas
Oct 2 '15 at 10:39
1
1
see: unix.stackexchange.com/questions/62950/â¦
â cas
Oct 2 '15 at 10:44
see: unix.stackexchange.com/questions/62950/â¦
â cas
Oct 2 '15 at 10:44
@cas you're right. As I wrote I've still many things to learn on bash scripting.
â Stefano Radaelli
Oct 2 '15 at 10:57
@cas you're right. As I wrote I've still many things to learn on bash scripting.
â Stefano Radaelli
Oct 2 '15 at 10:57
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
If you put the assignments before the script
ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' ./test.sh
the variables are available in the script's environment. The -k option treats all assignments, not just pre-command assignments, as environment modifications.
set -k
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
set +k
In either case, eval is not required at all and can be removed.
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
For the first example (x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.
â michael
Oct 3 '15 at 13:21
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If you put the assignments before the script
ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' ./test.sh
the variables are available in the script's environment. The -k option treats all assignments, not just pre-command assignments, as environment modifications.
set -k
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
set +k
In either case, eval is not required at all and can be removed.
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
For the first example (x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.
â michael
Oct 3 '15 at 13:21
add a comment |Â
up vote
2
down vote
accepted
If you put the assignments before the script
ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' ./test.sh
the variables are available in the script's environment. The -k option treats all assignments, not just pre-command assignments, as environment modifications.
set -k
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
set +k
In either case, eval is not required at all and can be removed.
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
For the first example (x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.
â michael
Oct 3 '15 at 13:21
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If you put the assignments before the script
ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' ./test.sh
the variables are available in the script's environment. The -k option treats all assignments, not just pre-command assignments, as environment modifications.
set -k
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
set +k
In either case, eval is not required at all and can be removed.
If you put the assignments before the script
ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano' ./test.sh
the variables are available in the script's environment. The -k option treats all assignments, not just pre-command assignments, as environment modifications.
set -k
./test.sh ip='164.130.21.98' hostname='whatever' pwd='/test' ftpcmd='CWD debug' user='stefano'
set +k
In either case, eval is not required at all and can be removed.
answered Oct 2 '15 at 15:14
chepner
5,2001223
5,2001223
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
For the first example (x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.
â michael
Oct 3 '15 at 13:21
add a comment |Â
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
For the first example (x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.
â michael
Oct 3 '15 at 13:21
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
In such case your suggestion is to have to to a parent shell that runs test.sh. Am I right?
â Stefano Radaelli
Oct 2 '15 at 15:50
For the first example (
x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.â michael
Oct 3 '15 at 13:21
For the first example (
x=1 y="abc" ./cmd.sh), no, you are simply reordering the command.â michael
Oct 3 '15 at 13:21
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f233467%2fbash-error-on-eval-containing-blank-space%23new-answer', 'question_page');
);
Post as a guest
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
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
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
2
don't reinvent the wheel. option parsing was done years ago. use
getopts(bash built-in, short single-letter options only) or/usr/bin/getopt(from util-linux, supports both short and --long options)â cas
Oct 2 '15 at 10:39
1
see: unix.stackexchange.com/questions/62950/â¦
â cas
Oct 2 '15 at 10:44
@cas you're right. As I wrote I've still many things to learn on bash scripting.
â Stefano Radaelli
Oct 2 '15 at 10:57