You can accept input from the keyboard and assign an input value to a user defined shell variable using .
Contents
variable1 variable2 variableN
Where,
-p "Prompt" : Display prompt to user without a newline.
variable1 : The first input (word) is assigned to the variable1.
variable2 : The second input (word) is assigned to the variable2.
Create a script called greet.sh as follows:
name
. Let us be friends!"
Save and close the file. Run it as follows:
+x greet.sh
.greet.sh
Sample Outputs:
Enter your name : Vivek Gite
Hi,Vivek Gite. Let us be friends!
Try the following examples.
n1
n2
n3
"""
A shell script to display the Internet domain name owner information (domain.sh):
domain_name
You can time out read command using the -t option. It causes read to time out and return failure if a complete line of input is not read within TIMEOUT seconds. For example,if no input provided within 10 second,program will be aborted (domain2.sh):
domain_name
The -s option causes input coming from a terminal do not be displayed on the screen. This is useful for password handling (readpass.sh):
my_password
"
Consider the following example:
"
Sample outputs:
Enter directory to delete : foo bar /tmp/data
foo bar /tmp/data
You will see a whitespace which is nothing but a space,a tab,and a newline (default). You can print actual values of IFS using the following command (see ):
"
Sample outputs:
^I$
$
Where,
$ - end of line i.e. newline
^I$ - tab and newline
Create a variable called nameservers and give it total 3 values as follows (note all values are separated by a whitespace):
=
Display the value of a variable nameservers with or :