• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to write Bash Script with variables on Ubuntu 21.04

  • 00:52 lsb_release -a
  • 01:08 sudo -s
  • 01:18 vi test.sh
  • 01:23 cd ~
  • 07:08 sh test.sh
{{postValue.id}}

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

Tags:
isaac
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is shell scripting?

A

A shell script is a text file that contains a sequence of commands for a UNIX-based operating system.

Q

Is Bourne Again a Linux shell?

A

Bash (Bourne Again Shell ) is the free version of the Bourne shell distributed with Linux and GNU operating

Q

What is the difference between shell and terminal?

A

A shell is a user interface for access to an operating system's services. ... The terminal is a program that opens a graphical window and lets you interact with the shell.

Q

What is variable shell scripting?

A

A variable is a character string to which we assign a value. The value assigned could be a number, text, filename, device, or any other type of data

Q

What is shell script extension?

A

The shell script extension is .sh

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 Isaac ?
How to run windows application in linux

I need to run the windows application in my Linux machine, instead of installing from yum repo or any other repos. How to do that..??

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.