• 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 create a Bash Script to get User Data on Oracle Linux 9.2

  • 00:34 cat /etc/os-release
  • 00:49 vim userdata1
  • 02:39 chmod +x userdata1
  • 02:54 ll
  • 03:04 ./userdata1
  • 03:30 vim userdata2
  • 06:43 chmod +x userdata2
  • 06:57 ll
  • 07:08 ./userdata2
  • 07:26 ./userdata2
  • 07:52 vim userdata3
  • 10:15 chmod +x userdata3
  • 10:26 ll
  • 10:40 ./userdata3
{{postValue.id}}

To create a Bash Script to get User Data

Introduction:

To read the Bash user input, we use the built-in Bash command called read. It takes input to read the Bash user input, we use the built-in Bash command called read. It takes input from the user and assigns it to the variable. It reads only a single line from the Bash shell from the user and assigns it to the variable.

Installation steps:

Step 1: Check the OS version by using the below command

[root@linuxhelp ~]# cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="9.2"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Oracle Linux Server 9.2"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:9:2:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://github.com/oracle/oracle-linux"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 9"
ORACLE_BUGZILLA_PRODUCT_VERSION=9.2
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=9.2

Step 2: Create a script file use of read command without variable by using the Vim command

[root@linuxhelp ~]# vim userdata1
#!/bin/bash
echo "What is your favorite programming language?"
# Take input without defining variable
read
# Print the input value
echo "Your answer is $REPLY"

Step 3: Execute the script first change the executable file permission by using the below command

[root@linuxhelp ~]# chmod +x userdata1

Step 4: List the file by using the below command

[root@linuxhelp ~]# ll
total 8
-rw-------. 1 root root 1062 Sep  4 17:37 anaconda-ks.cfg
-rwxr-xr-x. 1 root root  174 Sep  7 11:46 userdata1

Step 5: Execute the script by using the below command

[root@linuxhelp ~]# ./userdata1
What is your favorite programming language?
Linux
Your answer is Linux

Step 6: Create a script file using read command with options by Vim command

[root@linuxhelp ~]# vim userdata2
#!/bin/bash
# Type your Login Information
read -p 'Username: ' user
read -sp 'Password: ' pass

# Check the username and password are valid or not
if (( $user == "admin" && $pass == "12345" ))
then
    echo -e "\nSuccessful login"
else
    echo -e "\nUnsuccessful login"
fi

Step 7: Execute the script first change the executable file permission by using the below command

[root@linuxhelp ~]# chmod +x userdata2

Step 8: List the file by using the below commands

[root@linuxhelp ~]# ll
total 12
-rw-------. 1 root root 1062 Sep  4 17:37 anaconda-ks.cfg
-rwxr-xr-x. 1 root root  174 Sep  7 11:46 userdata1
-rwxr-xr-x. 1 root root  274 Sep  7 12:11 userdata2

Step 9: Execute the script by using the below commands

[root@linuxhelp ~]# ./userdata2
Username: linuxhelp
Password:
Successful login
[root@linuxhelp ~]# ./userdata2
Username: linuxhelp
Password:
Unsuccessful login

Step 10: Create a script file using read command to take multiple inputs by using the Vim command

[root@linuxhelp ~]# vim userdata3
#!/bin/bash
## Taking multiple inputs
echo "Type four names"
read lan1 lan2 lan3 lan4
echo "$lan1 is your first choice"
echo "$lan2 is your second choice"
echo "$lan3 is your third choice"
echo "$lan4 is your fourth choice"

Step 11: To execute the script, first change the executable file permission by using the below command

[root@linuxhelp ~]# chmod +x userdata3

Step 12: List the file by using the below commands

[root@linuxhelp ~]# ll
total 16
-rw-------. 1 root root 1062 Sep  4 17:37 anaconda-ks.cfg
-rwxr-xr-x. 1 root root  174 Sep  7 11:46 userdata1
-rwxr-xr-x. 1 root root  274 Sep  7 12:11 userdata2
-rwxr-xr-x. 1 root root  224 Sep  7 16:34 userdata3

Step 13: Execute the script by using the below commands

[root@linuxhelp ~]# ./userdata3
Type four names
Welcome to Linuxhelp .com
Welcome is your first choice
to is your second choice
Linuxhelp is your third choice
.com is your fourth choice

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to create a Bash Script to get User Data on Oracle Linux 9.2. Your feedback is much welcome.

Tags:
michael
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How can you collect user input in a bash script?

A

We have used the read command to get the user input in the variable name.

Q

What is $() in Bash?

A

$( command ) or. ` command ` Bash performs the expansion by executing the command in a subshell environment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.

Q

I have 2 files and I want to print the records that are common to both.

A

We can use tail –f filename. This will cause only the default last 10 lines to be displayed on std o/p which continuously shows the updating part of the file.

Q

What are the advantages of using bash scripts?

A

Bash script has many advantages which are described below:
• It is easy to use and learn.
• Many manual tasks that need to run frequently can be done automatically by writing a bash script.
• The sequence of multiple shell commands can be executed by a single command.
• Bash script written in one Linux operating system can easily execute in other Linux operating systems. So, it is portable

Q

Mention the disadvantages of bash scripts

A

Some disadvantages of the bash script are mentioned below:
• It works slower than other languages.
• The improper script can damage the entire process and generate a complicated error.

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 Luke ?
workbench for debian

I am using workbench in CentOS whereas now I need to use Debian Operating system so could you please help to install and use in Debian?

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.