Score:0

How to excute several commands with one command

us flag

Usually I need to exceute several commands every time Im at work, start local server, start docker bash, run frontend service...and I wish I could do all those stuff with one single command.

I tried using an alias, but the implementation I saw were more in the field of making long commands shorter, but I wasn't able to make an alias with several commands.

Any idea if is possible to run a series of commands one after the other with one single command?

Artur Meinild avatar
vn flag
It seems it should actually be pointed to [this answer](https://askubuntu.com/questions/334941/how-to-combine-multiple-commands-in-terminal) instead, as the one pointed to is also a duplicate.
muru avatar
us flag
@ArturMeinild yes, but the current dupe has some examples (https://askubuntu.com/a/497869/158442, https://askubuntu.com/a/497868/158442) which are more directly applicable to OP's problem.
Score:2
vn flag

You can chain several commands directly on the command line.

One option is to use a semicolon, like this:

command1; command2; command3

This will fire all 3 commands after each other, unconditionally.

You can also use a logical operator, like this:

command1 && command2 && command3

&& is an "and" operator, and in this case command2 will only execute if command1 is successful etc.

You can also use this construction in aliases (with no need for a script), like this:

alias mycommand='command1; command2; command3'
Score:1
de flag
ob2

Running several commands is pretty simple thanks to a script. Create any text file you want (e.g. a hidden file into your home).

gedit ~/.myscript.sh

Put the following content

#!/bin/bash

<my command 1>
<my command 2>
...

Make the file executable.

chmod +x ~/.myscript.sh

Then you can run the script with the following command.

~/.myscript.sh

Finally, you can add an alias into your ~/.bashrc.

alias mycommand=~/.myscript.sh

So you can use mycommand to execute your script.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.