3

There are certain sequences of commands I usually type in a console one after the other, e.g.

adb devices
adb uninstall com.package.abc
cd myProjectDir
meteor reset
rm -f -r .meteor/local
meteor run android-device

How can I write a script which lets me execute all (or at least a part of) these commands in one row (e.g. ./batchRunMeteor)?

1 Answer 1

2

Three ways:

A) run some number of commands in one row, linked with semicolons

adb devices; adb uninstall com.package.abc; cd myProjectDir; meteor reset; rm -f -r .meteor/local; meteor run android-device

Here I've kept the original "intent" of simple sequential execution. One recommendation would be to run subsequent commands only if the preceding one(s) succeeded; that's accomplished with && :

adb devices && adb uninstall com.package.abc && cd myProjectDir && meteor reset && rm -f -r .meteor/local && meteor run android-device

B) create an alias

alias batchRunMeteor='adb devices; adb uninstall com.package.abc; cd myProjectDir; meteor reset; rm -f -r .meteor/local; meteor run android-device'
# or use the && method:
alias batchRunMeteor='adb devices && adb uninstall com.package.abc && cd myProjectDir && meteor reset && rm -f -r .meteor/local && meteor run android-device'
batchRunMeteor

C) create a shell script

cat > batchRunMeteor << EOF
adb devices
adb uninstall com.package.abc
cd myProjectDir
meteor reset
rm -f -r .meteor/local
meteor run android-device
EOF

chmod u+x batchRunMeteor 
./batchRunMeteor 

The shell script can also use && as desired.

2
  • thank you Jeff. can you please explain c:), particularly the first line (cat > batchRunMeteor << EOF)?
    – dragonmnl
    Oct 17, 2015 at 22:25
  • sure; that's just one way to get those lines into a file; feel free to use your favorite editor instead. The "<<" redirect syntax says to take the remaining lines until you see the indicator again; here, the I called indicator "EOF", but you can call it anything you want. The ">" redirection puts those lines into a file of the given name (batchRunMeteor).
    – Jeff Schaller
    Oct 17, 2015 at 22:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .