The Linux shell is a text-based user interface that allows Linux users to execute commands in the Linux operating system. The Linux Shell can be accessed in different ways by logging into your Linux machine or opening up a terminal window on your desktop.
With the Linux Shell, you can do anything from executing one command at a time to running complex scripts and applications. This article will show you how to use the Linux Shell to execute multiple commands.
Running multiple commands can be handy, efficient and also reduce deployment steps if using a Dockrfile.
Options (; or &&)
When executing multiple commands, we have two options, as shown in the table. We use either ; or && depending on how we would like to execute the following command.
|command A; command B||Run command A and then command B regardless of success|
|command A && command B||Run command B if command A finished successfully|
It probably makes more sense to use && if the commands are dependent because it ensures the previous command finished successfully. If it doesn’t matter, use ;