How To Create And Run Bash script on Linux mint 20.2
To Create and Bash Script On Linux Mint
Introduction:
It is convention to give files that are Bash scripts an extension of .sh (myscript.sh for example). As you would be aware Linux is an extensionless system so a script doesn't necessarily have to have this characteristic in order to work.
Installation procedure :
Step 1 : To Check the os version
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Linuxmint
Description: Linux Mint 20.2
Release: 20.2
Codename: uma
Step 2 : Creating the touch file by uding the following command
root@linuxhelp:~# touch testscript.sh
Step 3 : Changing the permission to the below file
root@linuxhelp:~# chmod 755 testscript.sh
Step 4 : Long list the file by using the following command
root@linuxhelp:~# ls -la
total 49784
drwx------ 5 root root 4096 Jan 6 06:32 .
drwxr-xr-x 19 root root 4096 Jan 4 09:07 ..
-rw------- 1 root root 4467 Jan 6 06:03 .bash_history
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
drwx------ 3 root root 4096 Jul 3 2021 .cache
drwx------ 3 root root 4096 Jan 4 04:36 .dbus
-rw-r--r-- 1 root root 19666 Jan 6 04:35 index.html
drwxr-xr-x 3 root root 4096 Jan 5 04:28 .local
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
-rw-r--r-- 1 root root 50916586 Sep 30 02:59 rstudio-server-2021.09.0-351-amd64.deb
-rwxr-xr-x 1 root root 0 Jan 6 06:32 testscript.sh
-rw-r--r-- 1 root root 168 Jan 6 04:35 .wget-hsts
Step 5 : Editing the testscript.sh file
root@linuxhelp:~# nano testscript.sh
#!/bin/bash
echo bash script is started
ping -c 7 192.168.6.180
ls –la
echo bash script completed
Step 6 : Running the testscript.sh by using the following command
root@linuxhelp:~# ./testscript.sh
bash script is started
PING 192.168.7.200 (192.168.7.200) 56(84) bytes of data.
64 bytes from 192.168.7.200: icmp_seq=1 ttl=64 time=3.82 ms
64 bytes from 192.168.7.200: icmp_seq=2 ttl=64 time=0.499 ms
64 bytes from 192.168.7.200: icmp_seq=3 ttl=64 time=1.16 ms
64 bytes from 192.168.7.200: icmp_seq=4 ttl=64 time=1.09 ms
64 bytes from 192.168.7.200: icmp_seq=5 ttl=64 time=0.593 ms
64 bytes from 192.168.7.200: icmp_seq=6 ttl=64 time=1.45 ms
64 bytes from 192.168.7.200: icmp_seq=7 ttl=64 time=1.40 ms
--- 192.168.7.200 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6018ms
rtt min/avg/max/mdev = 0.499/1.429/3.819/1.032 ms
total 49788
drwx------ 5 root root 4096 Jan 6 06:34 .
drwxr-xr-x 19 root root 4096 Jan 4 09:07 ..
-rw------- 1 root root 4467 Jan 6 06:03 .bash_history
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
drwx------ 3 root root 4096 Jul 3 2021 .cache
drwx------ 3 root root 4096 Jan 4 04:36 .dbus
-rw-r--r-- 1 root root 19666 Jan 6 04:35 index.html
drwxr-xr-x 3 root root 4096 Jan 5 04:28 .local
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
-rw-r--r-- 1 root root 50916586 Sep 30 02:59 rstudio-server-2021.09.0-351-amd64.deb
-rwxr-xr-x 1 root root 107 Jan 6 06:34 testscript.sh
-rw-r--r-- 1 root root 168 Jan 6 04:35 .wget-hsts
bash script completed
With this process of creating and Running bash script On Linux mint 20.2 has comes to an end.
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.
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.
Shell scripts are usually implemented by interpreters present in the Linux kernel.
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
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).
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
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.
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.