Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
3 fix the quotes
source | link

Use set -x to see what the shell really tries to run:

$ command="findcommand='find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;"\;'
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.

The double quotes accomplish the same function as the backslash would, escaping the semicolon so that it's taken as a character, and not a command separator.

These should be equivalent:

$ foo="something ;"
$ foo=something\ \;

Also, note that running a command line with $command is a bit hairy: if you have spaces in any of the arguments going to the resulting command (e.g. in the pathname you have in $where), they will get split. Shell arrays give a more robust way to do that.

Use set -x to see what the shell really tries to run:

$ command="find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;"
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.

The double quotes accomplish the same function as the backslash would, escaping the semicolon so that it's taken as a character, and not a command separator.

These should be equivalent:

$ foo="something ;"
$ foo=something\ \;

Also, note that running a command line with $command is a bit hairy: if you have spaces in any of the arguments going to the resulting command (e.g. in the pathname you have in $where), they will get split. Shell arrays give a more robust way to do that.

Use set -x to see what the shell really tries to run:

$ command='find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;'
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.

The double quotes accomplish the same function as the backslash would, escaping the semicolon so that it's taken as a character, and not a command separator.

These should be equivalent:

$ foo="something ;"
$ foo=something\ \;

Also, note that running a command line with $command is a bit hairy: if you have spaces in any of the arguments going to the resulting command (e.g. in the pathname you have in $where), they will get split. Shell arrays give a more robust way to do that.

2 added 508 characters in body
source | link

Use set -xset -x to see what the shell really tries to run:

$ command="find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;"
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.

The double quotes accomplish the same function as the backslash would, escaping the semicolon so that it's taken as a character, and not a command separator.

These should be equivalent:

$ foo="something ;"
$ foo=something\ \;

Also, note that running a command line with $command is a bit hairy: if you have spaces in any of the arguments going to the resulting command (e.g. in the pathname you have in $where), they will get split. Shell arrays give a more robust way to do that.

Use set -x to see what the shell really tries to run:

$ command="find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;"
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.

Use set -x to see what the shell really tries to run:

$ command="find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;"
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.

The double quotes accomplish the same function as the backslash would, escaping the semicolon so that it's taken as a character, and not a command separator.

These should be equivalent:

$ foo="something ;"
$ foo=something\ \;

Also, note that running a command line with $command is a bit hairy: if you have spaces in any of the arguments going to the resulting command (e.g. in the pathname you have in $where), they will get split. Shell arrays give a more robust way to do that.

1
source | link

Use set -x to see what the shell really tries to run:

$ command="find foo -iname "TEST*" -exec grep --color -F -Hn "main" {} \;"
$ echo "$command"
find foo -iname TEST* -exec grep --color -F -Hn main {} \;
$ set -x
$ $command
+ find foo -iname 'TEST*' -exec grep --color -F -Hn main '{}' '\;'
find: missing argument to `-exec'

Note the '\;': you're giving find a literal backslash, which isn't what it expects.