Scripts examples with read command
[davsingh@noisecover-dr Scripts]$ read test
davinder singh
[davsingh@noisecover-dr Scripts]$ echo $test
davinder singh
[davsingh@noisecover-dr Scripts]$ read firstname lastname
davinder singh
[davsingh@noisecover-dr Scripts]$ echo $firstname
davinder
[davsingh@noisecover-dr Scripts]$ echo $lastname
singh
[davsingh@noisecover-dr Scripts]$ echo $firstname $lastname
davinder singh
davinder singh
[davsingh@noisecover-dr Scripts]$ echo $test
davinder singh
[davsingh@noisecover-dr Scripts]$ read firstname lastname
davinder singh
[davsingh@noisecover-dr Scripts]$ echo $firstname
davinder
[davsingh@noisecover-dr Scripts]$ echo $lastname
singh
[davsingh@noisecover-dr Scripts]$ echo $firstname $lastname
davinder singh
Adding a few more here
ReplyDelete[anil@indian ~]$ read -p "enter your name : " yourname
enter your name : anil
It gives better readability
[anil@indian ~]$ read -s name
[anil@indian ~]$ echo $name
anil
hiding while writing the input
always use -s before -p , in case you want to use both of them.