Execute Multiple Commands On Linux Shell

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 BRun command A and then command B regardless of success
command A && command BRun 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 ;

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.