• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

How to create and run a bash script on Ubuntu 21.04

  • 00:45 lsb_release -a
  • 01:00 sudo -s
  • 01:10 cd /root/
  • 01:18 touch testscript.sh
  • 01:39 chmod 755 testscript.sh
  • 01:49 ls -la
  • 02:01 vi testscript.sh
6674

To Create and Run Bash Script on Ubuntu 21.04

Introduction

Bash is an acronym for “Bourne-Again Shell”. It is also used as a command-line interpreter for both UNIX and Linux. The BASH script also contains a series of commands that will later be executed while running the script. The bash script should also be commenced as #!/bin/bash.

Installation Procedure:

Checking the Ubuntu OS version installed

linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Log in as root user

linuxhelp@linuxhelp:~$ sudo -s
[sudo] password for linuxhelp: 

Change to root directory

root@linuxhelp:/home/linuxhelp# cd /root/

Create file named testscript.sh

root@linuxhelp:~# touch testscript.sh

Assign Permissionto testscript.shfile

root@linuxhelp:~# chmod 755 testscript.sh 

Long listing the files

root@linuxhelp:~# ls -la
total 32
drwx------  4 root root 4096 Sep 30 08:51 .
drwxr-xr-x 20 root root 4096 Sep  8 16:50 ..
-rw-------  1 root root 1991 Sep 30 08:47 .bash_history
-rw-r--r--  1 root root 3106 Aug 15  2019 .bashrc
drwx------  2 root root 4096 Apr 20 16:20 .cache
-rw-r--r--  1 root root  161 Sep 16  2020 .profile
drwxr-xr-x  3 root root 4096 Sep  8 17:00 snap
-rwxr-xr-x  1 root root    0 Sep 30 08:51 testscript.sh
-rw-r--r--  1 root root   17 Sep 27 12:51 .vimrc

Editing the testscript.sh file

root@linuxhelp:~# vi testscript.sh 

Snap 1

Run the testscript.sh

root@linuxhelp:~# ./testscript.sh 
Bash script is started
PING 192.168.7.150 (192.168.7.150) 56(84) bytes of data.
64 bytes from 192.168.7.150: icmp_seq=1 ttl=63 time=0.633 ms
64 bytes from 192.168.7.150: icmp_seq=2 ttl=63 time=0.723 ms
64 bytes from 192.168.7.150: icmp_seq=3 ttl=63 time=0.699 ms
64 bytes from 192.168.7.150: icmp_seq=4 ttl=63 time=0.961 ms
64 bytes from 192.168.7.150: icmp_seq=5 ttl=63 time=0.712 ms

--- 192.168.7.150 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4080ms
rtt min/avg/max/mdev = 0.633/0.745/0.961/0.112 ms
total 36
drwx------  4 root root 4096 Sep 30 08:53 .
drwxr-xr-x 20 root root 4096 Sep  8 16:50 ..
-rw-------  1 root root 1991 Sep 30 08:47 .bash_history
-rw-r--r--  1 root root 3106 Aug 15  2019 .bashrc
drwx------  2 root root 4096 Apr 20 16:20 .cache
-rw-r--r--  1 root root  161 Sep 16  2020 .profile
drwxr-xr-x  3 root root 4096 Sep  8 17:00 snap
-rwxr-xr-x  1 root root  108 Sep 30 08:53 testscript.sh
-rw-r--r--  1 root root   17 Sep 27 12:51 .vimrc
Bash script completed

Snap 2

With this step creating and running the bash script file is completed

Tags:
samson
Author: 

Comments ( 0 )

No comments available

Add a comment

Frequently asked questions ( 5 )

Q

Is shell scripting and bash scripting are the same?

A

Bash is the acronym for "Bourne Again Shell", which is also considered to be a subset of the shell scripting.
Shell scripting is scripting in any shell and eases the interaction between the user and operating system, while bash scripting can be done only for the bash.

Q

Is bash a terminal or shell?

A

Image result for bash vs shell
The GUI window refers to the terminal and it can also be seen on the screen as it requires commands and shows the output.
The bash is particularly a shell and the primary example for it is sh(bourne shell), csh(c shell), and tcsh(turbo c shell).

Q

What is the difference between C shell and bash?

A

CSH is a C shell while BASH stands for Bourne Again shell. The two are both Unix and Linux shells. whereas the C-shell commands start with '#' and for bash it is ‘;’. The CSH also its own set of features and the BASH unites the features of other shells.

Q

What language is Linux terminal?

A

The language that is commonly used is a shell script that is sometimes referred to as “shebang”.
Shell scripts are usually implemented by interpreters present in the Linux kernel.

Q

Can Python replace bash?

A

The answer is yes as using python provides various benefits and it can be also installed by default on all the major Linux distributions.

Related Tutorials in How to create and run a bash script on Ubuntu 21.04

Related Tutorials in How to create and run a bash script on Ubuntu 21.04

How to install Meld tool in Ubuntu
How to install Meld tool in Ubuntu
Feb 25, 2017
How to install Dconf-Editor on Ubuntu 18.04
How to install Dconf-Editor on Ubuntu 18.04
Jul 14, 2018
How to install and update OpenSSL on Ubuntu 16.04
How to install and update OpenSSL on Ubuntu 16.04
Mar 9, 2017
How to install GLib 2.0 on Ubuntu 17.04
How to install GLib 2.0 on Ubuntu 17.04
May 22, 2017
How to Install Android Emulator on Ubuntu 20.4.1
How to Install Android Emulator on Ubuntu 20.4.1
Jul 13, 2021
How To Install AnyDesk on Ubuntu 16.04
How To Install AnyDesk on Ubuntu 16.04
Apr 4, 2018
How to install Genymotion 2.12.1 on Ubuntu 18.04
How to install Genymotion 2.12.1 on Ubuntu 18.04
Jul 9, 2018
How to install Timeshift 18.4 on Ubuntu 18.04
How to install Timeshift 18.4 on Ubuntu 18.04
Jul 6, 2018

Related Forums in How to create and run a bash script on Ubuntu 21.04

Related Forums in How to create and run a bash script on Ubuntu 21.04

Ubuntu
matthew class=
Failed to enable unit: Refusing to operate on linked unit file sshd.service
Apr 15, 2019
Ubuntu
mason class=
Passwd: You may not view or modify password information for root On Ubuntu 19.04
May 27, 2019
Ubuntu
isaac class=
/etc/apt/sources.list Permission denied
May 18, 2017
Ubuntu
yousuf class=
lsb_release command not working : Debian
Jan 18, 2018
ifconfig command
jackbrookes class=
what is the location of the ifconfig program on your machine?
Jan 4, 2018
Ubuntu
mason class=
"E: Package 'php-mcrypt' has no installation candidate" error on Ubuntu 20.4.1
Mar 15, 2021
NFS
luke class=
clnt_create: RPC: Program not registered
Apr 25, 2017
Apache
isaac class=
How to disable apache welcome page on Ubuntu
Dec 15, 2018

Related News in How to create and run a bash script on Ubuntu 21.04

Related News in How to create and run a bash script on Ubuntu 21.04

How To Install Mixxx on Ubuntu 16.04
How To Install Mixxx on Ubuntu 16.04
Oct 11, 2017
Ubuntu 17.04 released with greater expectations
Ubuntu 17.04 released with greater expectations
Apr 15, 2017
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Ubuntu Core now available on i.MX6 based TS-4900 thanks to Technologic Systems Inc.
Mar 1, 2017
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Ubuntu 17.10 Artful Aardvark Beta 1 is now here. Download Now
Sep 2, 2017
Ubuntu Unity is no more: One Linux dream has been axed
Ubuntu Unity is no more: One Linux dream has been axed
Apr 7, 2017
What’s next for Ubuntu Linux Desktop?
What’s next for Ubuntu Linux Desktop?
Apr 11, 2017
Say Hi to Ubuntu's new mascot
Say Hi to Ubuntu's new mascot
Mar 22, 2019
KDE Connect App was removed from Google Play Store and brought back in 24 hours
KDE Connect App was removed from Google Play Store and brought back in 24 hours
Mar 22, 2019
Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Owen ?
How to add SSH key to my Gitlab account

I need to add the SSH key in my gitlab account. How to do so ????

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.