Created
January 13, 2010 19:21
-
-
Save apinstein/276500 to your computer and use it in GitHub Desktop.
shell script hrm...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# shell script quoting problem demonstration | |
# I need to be able to set a shell variable with a command with some options, like so | |
PHP_COMMAND="php -d 'include_path=/path/with spaces/dir'" | |
# then use PHP_COMMAND to run something in another script, like this: | |
$PHP_COMMAND -r 'echo get_include_path();' | |
# the above fails when executed. However, if you copy/paste the put from this line and run it in the CLI, it works! | |
echo "$PHP_COMMAND -r 'echo get_include_path();'" | |
php -d include_path='/path/with spaces/dir' -r 'echo get_include_path();' | |
# what's going on? | |
# this is also interesting | |
echo "\n--------------------" | |
# this works great, but only works if include_path doesn't need quoting | |
PHP_COMMAND="php -d include_path=/path/to/dir" | |
echo "$PHP_COMMAND -r 'echo get_include_path();'" | |
$PHP_COMMAND -r 'echo get_include_path();' | |
echo "\n--------------------" | |
# this one doesn't when run in the sh script, but again if you copy/paste the output it does work as expected. | |
PHP_COMMAND="php -d 'include_path=/path/to/dir'" | |
echo "$PHP_COMMAND -r 'echo get_include_path();'" | |
$PHP_COMMAND -r 'echo get_include_path();' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment