How to write Bash Script with variables on Ubuntu 21.04
To write Bash Script with variables on Ubuntu 21.04
Introduction
Bash scripts are text files containing various commands. We can put any command that can be executed on the terminal into a Bash script. Variables may be added anywhere in a script (or on the command line for that matter) and Bash will replace them with the value of the variable when they are run.
Installation Procedure
Check the OS version
linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
Log on to Root user by using the following command
linuxhelp@linuxhelp:~$ sudo -s
[sudo] password for linuxhelp:
Changing to Home Directory
root@linuxhelp:/home/linuxhelp# cd ~
Creating a script file by using thefollowing command
root@linuxhelp:~# vi test.sh
#!/bin/bash
echo Enter your Name
read NAME
echo Enter your Age
read AGE
echo Enter your Number
read NUM
echo Enter your Mail
read MAIL
echo "Details you provided"
echo Your name is $NAME
echo Your age is $AGE
echo Your Number is $NUM
echo Your mail is $MAIL
echo Registration completed
Executing Script file by using the following command
root@linuxhelp:~# sh test.sh
Enter your Name
Musk
Enter your Age
25
Enter your Number
987654321
Enter your Mail
musk@gmail.com
Details you provided
Your name is Musk
Your age is 25
Your Number is 987654321
Your mail is musk@gmail.com
Registration completed
By this writing Bash Script with variables comes to an End
Comments ( 0 )
No comments available