Script to execute commands in sequence php
Clash Royale CLAN TAG#URR8PPP
Script to execute commands in sequence php
I'm trying to figure out how to write a script that will essentially execute one after the other (provided the previous command has finished).
php bin/console SOME:CUSTOM:COMMAND <PART_1_ARGUMENT> <PART_2_ARGUMENT> --env=xxx
e.g. lets say I have the following as my arguments
then my command would work in order executing one after the other like
php bin/console COMMAND Apple pie --env=xxx
and then right after
php bin/console COMMAND Apple crumble --env=xxx
and so forth ?
Any info is helpful I've googled for hours .. (newbie)
Can't you just pass them as a list of arguments, and in your PHP script, loop through the inputs and call your logic/function for each input.
– Patrick Q
Aug 10 at 17:13
Not really sure if it's exactly a "duplicate", but see this question which a quick search turned up.
– Patrick Q
Aug 10 at 17:15
1 Answer
1
You can use a loop:
for args in "Apple pie" "Apple crumble" "Pear apple"
do
php bin/console COMMAND $args --env=xxx
done
One caveat: this won't work if any of the arguments can contain whitespace or wildcard characters. You can't quote $args
in the command line, because you need Apple
and pie
to be separate arguments. It wouldn't work to put quotes in the strings, because quotes aren't parsed when expanding variables. You could do it with two arrays:
$args
Apple
pie
arg1=("Apple" "Apple" "Pear")
arg2=("pie" "crumble" "apple")
for (( i=0; i < $#arg1[@]; i++ ))
do
php bin/console COMMAND "$arg1[$i]" "$arg2[$i]" --env=xxx
done
very useful! I compared what I had, I had a bunch on extra brackets etc. But knowing that about the "whitespace" I didn't know. It's 90% there I will work on trying to get it done because the loop doesn't fully cycle. It stops after the first one :)
– toddy
Aug 10 at 17:29
I just removed the let i=i+1 And the rest fell into place .. Thanks for your support @Barmar
– toddy
Aug 10 at 17:39
that was left over from an earlier while loop
– Barmar
Aug 10 at 19:04
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Just put the two commands right after each other in a shell script.
– Barmar
Aug 10 at 17:07