PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 22, 2022

[FIXED] How do I 'exec' a bash command like this where an option is multi-word?

 July 22, 2022     bash, double-quotes, escaping, exec, quotes     No comments   

Issue

On the commandline I can run my binary this way:

theBinary_exe -q 'more than one word' -f foo -b bar

When I put that in a bash script and run the script it's all fine. But if I do this in the script:

CMD="theBinary_exe -q 'more than one word' -f foo -b bar"
exec $CMD

The 'q' argument only passes the first word to the executable. I tried using \" as well with no luck. Is there a wrapping I can use to prevent that when I use exec?


Solution

Do not use a regular parameter.

Use an array:

args=( -q 'more than one word' -f foo -b bar)
theBinary_exe "${args[@]}"


Answered By - chepner
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing