1

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).

2
  • add an echo just before the final constructed command to see what is generated and potentially any errors. Commented Dec 12, 2013 at 2:34
  • @MattWilliamson I did that and the command that resulted ran fine manually in the terminal. Commented Dec 12, 2013 at 2:55

1 Answer 1

0

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.