Skip to main content
added 381 characters in body
Source Link
slm
  • 379.8k
  • 127
  • 793
  • 897

I think your issue is the use of eval. If you take your script and use arrays to store the commands prior to running this should be sufficient to execute those commands.

#!/bin/bash

CMD1=(echo "onecmd")
CMD2=(echoprintf "ascri*""%s\n" ascrip*)
CMD3='echo cmd3'

${CMD1[@]}
${CMD2[@]}
$CMD3

No need to run them through eval.

Example

$ ./ascript.bash 
onecmd
ascript.bash
cmd3

Debugging

You can see what's going on behind the scenes if you enable Bash's debug mode.

$ bash -x ./ascript.bash 
+ CMD1=(echo "onecmd")
+ CMD2=(printf "%s\n" ascrip*)
+ CMD3='echo cmd3'
+ echo onecmd
onecmd
+ printf '%s\n' ascript.bash
ascript.bash
+ echo cmd3
cmd3

I think your issue is the use of eval. If you take your script and use arrays to store the commands prior to running this should be sufficient to execute those commands.

#!/bin/bash

CMD1=(echo "onecmd")
CMD2=(echo "ascri*")

${CMD1[@]}
${CMD2[@]}

No need to run them through eval.

Example

$ ./ascript.bash 
onecmd
ascript.bash

I think your issue is the use of eval. If you take your script and use arrays to store the commands prior to running this should be sufficient to execute those commands.

#!/bin/bash

CMD1=(echo "onecmd")
CMD2=(printf "%s\n" ascrip*)
CMD3='echo cmd3'

${CMD1[@]}
${CMD2[@]}
$CMD3

No need to run them through eval.

Example

$ ./ascript.bash 
onecmd
ascript.bash
cmd3

Debugging

You can see what's going on behind the scenes if you enable Bash's debug mode.

$ bash -x ./ascript.bash 
+ CMD1=(echo "onecmd")
+ CMD2=(printf "%s\n" ascrip*)
+ CMD3='echo cmd3'
+ echo onecmd
onecmd
+ printf '%s\n' ascript.bash
ascript.bash
+ echo cmd3
cmd3
Source Link
slm
  • 379.8k
  • 127
  • 793
  • 897

I think your issue is the use of eval. If you take your script and use arrays to store the commands prior to running this should be sufficient to execute those commands.

#!/bin/bash

CMD1=(echo "onecmd")
CMD2=(echo "ascri*")

${CMD1[@]}
${CMD2[@]}

No need to run them through eval.

Example

$ ./ascript.bash 
onecmd
ascript.bash