0

I have some commands that take too long to execute so I need a bash script to execute them serially.

The commands:

cd ~/my_file 
command 1 
command 2
...
command n 

This is on Ubuntu 18.04. How should I do it?

3

Create a script using nano my-script.sh. Add shebang and the commands or path to commands.

#!/bin/bash
/path/to/command/1
/path/to/command/2
/path/to/command/3

Make it executable using chmod

chmod +x my-script.sh

And run it using

./my-script.sh

Or as a one line command in bash:

command1 && command2 && command3 && commandN

This would execute the commands only if the previous command was executed successfully.

| improve this answer | |
  • command1 && command2 && command3 && commandN would execute the commands only if the previous command was executed successfully. OTOH command1; command2; command3; commandN would executed all commands independently. – Kulfy Nov 24 '19 at 11:02
  • you can elaborate all the different ways on how to execute commands if you want : ) Feel free to edit the answer or write your own, i am too lazy : ) – AlexOnLinux Nov 24 '19 at 11:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.