Skip to main content
deleted 27 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 239

I constructed a command like this in a bash script

a="my_cmd";
a="$a --verbose";
echo $a;
$a;

It works and executes my command correctly. But when I add an environment variable to the mix it breaks.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
$a;

It breaks at "URL=myurl" saying No such file or directory, but if I run it using eval() the command works correctly.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
eval "$a";

Can someone kindly explain whyWhy adding environment variable to the mix broke my command in second example.

I constructed a command like this in a bash script

a="my_cmd";
a="$a --verbose";
echo $a;
$a;

It works and executes my command correctly. But when I add an environment variable to the mix it breaks.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
$a;

It breaks at "URL=myurl" saying No such file or directory, but if I run it using eval() the command works correctly.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
eval "$a";

Can someone kindly explain why adding environment variable to the mix broke my command in second example.

I constructed a command like this in a bash script

a="my_cmd";
a="$a --verbose";
echo $a;
$a;

It works and executes my command correctly. But when I add an environment variable to the mix it breaks.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
$a;

It breaks at "URL=myurl" saying No such file or directory, but if I run it using eval() the command works correctly.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
eval "$a";

Why adding environment variable to the mix broke my command in second example.

Source Link
Jithin
  • 143
  • 4

Running a constructed command from bash script

I constructed a command like this in a bash script

a="my_cmd";
a="$a --verbose";
echo $a;
$a;

It works and executes my command correctly. But when I add an environment variable to the mix it breaks.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
$a;

It breaks at "URL=myurl" saying No such file or directory, but if I run it using eval() the command works correctly.

a="my_cmd";
a="URL=myurl $a --verbose";
echo $a;
eval "$a";

Can someone kindly explain why adding environment variable to the mix broke my command in second example.