How to Save user inputs in a file with Bash Script on Debian 11.3
To save user inputs in a file with Bash Script on Debian 11.3
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 below Command
linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Step 2: Login as root user by using the below command
lnuxhelp@linuxhelp:~$ sudo -s
Step 3: Change to home directory by using the below Command
root@linuxhelp:/home/linuxhelp# cd
Step 4: Create the Bash Script file by using the below command
root@linuxhelp:~# nano 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 below command
root@linuxhelp:~# sh test.sh
what is your name?
linuxhelp
What is your age?
23
what is your qualification ?
BE
where are you from ?
India
Step 6: View the saved file by using the below command
root@linuxhelp:~# nano file.txt
Name : linuxhelp
Age : 23
Qualification : BE
Place : India
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to Save user inputs in a file with Bash Script on Debian 11.3. Your feedback is much welcome.
Comments ( 0 )
No comments available