Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Create and Run a Shell Script in Ubuntu 20.04 LTS

Learn how to create and Run a Shell Script in Ubuntu 20.04 LTS with clear steps, practical tips, and key considerations for completing the task safely.

Table of Contents

This guide explains how to create and Run a Shell Script in Ubuntu 20.04 LTS, with clear steps, practical tips, and important checks before you begin.

In this article, you will learn how to execute shell scripts through command line input. The article is using Ubuntu 20.04 LTS. Before showing how to execute shell scripts through the CLI, let's first look at how to create a shell script.

Create file with '. sh' extension

To create a '. sh' file, follow these steps:

1. Open the default editor through the menu bar

You can use the default editor in Ubuntu 20.04 LTS or if there is any other editor installed in your system, such as Vim. For this particular tutorial, the article is using the default editor.

Type 'editor' and click 'Text Editor'.

The default editor will be opened.

1. Open the default editor through the menu bar screenshot

2. Write commands in document without title and save it with '. sh' extension

You can write any command according to job requirements or assigned tasks. For this particular article, the following commands / codes will be written in the document without the title.

echo "Hello World" echo "Ubuntu 20.04 LTS tutorial" echo "Today's task"

Now save the file with the '. sh' extension in the directory of your choice. For this particular article, the file is saved in the default directory, which is the main directory named 'tutorial. sh'.

Now the script 'tutorial. sh' will look like this in the editor after it is saved.

2. Write commands in document without title and save it with '. sh' extension screenshot 2 Script 'tutorial. sh' in the editor

3. Execute the shell script 'tutorial. sh' through the CLI

You must execute the shell script via command line input.

First, you must make the shell script executable by running the following command:

$ ./scriptname

Replace your shell script name in the position of 'scriptname' in the above command. For this particular tutorial, the script name is 'tutorial. sh'.

3. Execute the shell script 'tutorial. sh' through the CLI screenshot 3 Makes the shell script executable

Run the script with the following command:

$ ./scriptname

The script name is 'tutorial. sh' as mentioned above.

When running the above command, the script line by line will be executed and display the following output:

3. Execute the shell script 'tutorial. sh' through the CLI screenshot 4

FAQ

What should I know about Create and Run a Shell Script in Ubuntu 20.04 LTS?

Focus on the key features, requirements, limitations, and practical use cases explained in this guide.

How do I get the best results with Create and Run a Shell Script in Ubuntu 20.04 LTS?

Follow the recommended steps, use current software or information, confirm compatibility, and review settings before major changes.

Are there any risks or limitations?

Potential limitations depend on compatibility, data quality, cost, privacy, support, and how the product or method is used.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.