How to create and run a bash script on Ubuntu 21.04
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
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
With this step creating and running the bash script file is completed
Comments ( 0 )
No comments available