How to create and run a shell script in Ubuntu 20.04 LTS
A script is used in Linux and commands are written into it according to job and task characteristics. When executing such a script, each of the commands will execute one by one in order. Shell is the command interpreter written by the user. Script shell helps users write and execute multiple commands at the same time.
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.
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.
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'.
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:
You should read it
- How to 'turn' Ubuntu into Windows
- Everything you can do with the new Windows 10 Bash Shell
- Use Google applications more efficiently with Google Apps Script
- Flow control in Shell
- What is Google Cloud Shell? What's remarkable about Cloud Shell?
- What is a shell?
- How to change the default shell in Windows Terminal
- How to use Open-Shell in Windows 11
May be interested
- Everything you can do with the new Windows 10 Bash Shellyou can install the linux environment and the bash shell on any version of windows 10. today's article will summarize what you can do in the new windows 10 bash shell.
- How to execute Shell script in Linuxexecuting shell scripts in linux is one of the essential skills that every linux user or administrator needs to master.
- How to use Open-Shell to create your own Start menu on Windows 10to address all of these existing problems, tipsmake found a free, open-source application that you can download today to create your own start menu - open-shell.
- What is Google Cloud Shell? What's remarkable about Cloud Shell?google cloud shell is an online development and operations environment that you can access anywhere via a web browser. cloud shell is a free service provided by google.
- What is a shell?shell is an environment in which we can run commands, programs and shell scripts. there are different versions of shell, which differ only from the version of the operating system. each version of shell has its own set of recognized commands and functions.
- Why is Ubuntu LTS preferred over regular distros?ubuntu is one of the most widely used linux distributions among software developers and other content creators. ubuntu is also used for many servers around the globe.
- How to use Open-Shell in Windows 11windows 11 has great out-of-the-box features and what makes it even better is that you can customize this operating system to your liking. however, there are limits to how much you can adjust.
- How to Customize Ubuntu 23.04 to Look Like macOSubuntu 23.04 lunar lobster, released in april 2023, brings many interesting features. despite stiff competition from operating systems like macos and windows, ubuntu still manages to create a niche for itself in the market.
- What's new in Ubuntu 18.04 LTS just released?ubuntu 18.04 lts code-named bionic beaver has just been officially launched on april 26th. this version is canonical's up to 5 year support period.
- Managing Windows networks using Script - Part 13: The script returns all valuesin the previous article of this series we came up with a script called displayclassproperties.vbs, which shows the names of the properties of the wmi class. this is what the script content is, by using win32_bootconfiguration as a class, we are connecting to the wmi nickname.