How to save user inputs in a file with Bash Script on Ubuntu 21.04
To Save user inputs in a file with Bash Script on Ubuntu 21.04
Introduction:
Bash scripts are computer programs that are run by the Unix shell, a command-line interpreter. They consist of a plain text file containing a series of commands. Shell scripts typically manipulate files, execute programs, and print text.
Step 1: Check the OS version by Using the Following Command
linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
Step 2: Login as root user by using the following command
lnuxhelp@linuxhelp:~$ sudo -s
Step 3:Changing to home directory by using Following Command
root@linuxhelp:/home/linuxhelp# cd ~
Step 4:Create the Bash Script file
root@linuxhelp:~# vi test.sh
#!/bin/bash
echo what is your name?
read name
echo What is your age?
read age
echo what is your qualification ?
read degree
echo where are you from ?
read place
echo Name : $name > file.txt
echo Age : $age >> file.txt
echo Qualification : $degree >> file.txt
echo Place : $place >> file.txt
Step 5:Run the Bash script by the following command
root@linuxhelp:~# sh test.sh
what is your name?
Aravind
What is your age?
23
what is your qualification ?
BE
where are you from ?
India
Step 6: Viewing the saved file
root@linuxhelp:~# vi file.txt
Name : Aravind
Age : 23
Qualification : BE
Place : India
By save user inputs in a file with Bash Script on Ubuntu 21.04 Comes to an end
Comments ( 0 )
No comments available