Reputation: 2282
I have the following lines in a BASH script:
ACTIONS_COMMAND="php -f $BASEDIR/scripts/activities.php < \"$SRC_DIR/%s/AndroidManifest.xml\""
printf -v ACTIONS_CMD "$ACTIONS_COMMAND" $FOLDER
$ACTIONS_CMD
This runs inside a loop to do the same operation to several Android applications.
When I echo the $ACTIONS_CMD
and copy and paste the command, it produces the correct output, but the script itself starts PHP, but does not copy the STDIN
. I know this because PHP hangs until I push Ctrl-D
on the keyboard and then it complains there was no input.
I tried switching the PHP command to
ACTIONS_COMMAND="cat \"$SRC_DIR/%s/AndroidManifest.xml\" | php -f $BASEDIR/scripts/activities.php"
When the first file name is in quotes (which I think it should be for safety), I get
cat: "apps/app_name/AndroidManifest.xml": No such file or directory
cat: |: No such file or directory
cat: php: No such file or directory
cat: -f: No such file or directory
<?php
... REST OF PHP SCRIPT ...
and without the quotes, it just outputs to the terminal window.
If it matters, it is GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
.
Upvotes: 2
Views: 66
Reputation: 16934
You cannot execute programs with input/output redirection in a string like that. It will attempt to use the pipe and angle characters and the file as input to the program you executed.
You need to pass that string to a shell in order to do the redirection.
One way to do that is:
bash -c "$ACTIONS_COMMAND"
Upvotes: 1