AMP AMP

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.

FAQ
Q
What is the first line of a bash script?
A
The bash first line in the script begins with a shebang (#!). These are two mandatory characters, after which is indicated which program you are using for scripting. Now it is bin/bash, but other programs use this mechanism. If you did not specify the program, bash will be used by default.
Q
What is bin bash?
A
/bin/bash is the most common shell used as the default shell for user login of the Linux system. The shell's name is an acronym for Bourne-again shell. Bash can execute the vast majority of scripts and thus is widely used because it has more features, is well-developed, and has better syntax.
Q
Is bash a scripting language?
A
Bash is a powerful programming language, one perfectly designed for use on the command line and in shell scripts. This three-part series explores using Bash as a command-line interface (CLI) programming language.
Q
What are the advantages of using bash scripts?
A
There are several advantages to using bash scripts and only a few disadvantages.
Advantages of Bash Scripts
Simple to create.
Can run multiple commands easily.
Interactive debugging.
Portable.
Time-saving.
Cost-effective.
Can be automated.
Q
What are Bash scripts used for?
A
Bash scripting is a useful tool for a developer to utilize in increasing productivity and managing menial, repetitive tasks. A script, with proper set permissions and syntax, can execute commands in a fraction of the time a user would take.