Read and Display name in Shell
# program to read a name and Display itSave the above Code as "readname.sh"
echo Enter Your Name
read name
echo "Your Name is " $name
Now to Execute this code "sh filename.sh" in terminal
See Output of the Code
Now Lets See How this Code works
All Lines starting with a # is a comment that is it will be neglected while the code is being executed.
The Second line there is "echo Enter Your Name" . echo is used to display the Contents on the Screen & this works similar to the printf function in C Language
The Third there is read name . this will read a string from the user here we have used the word "name". This works similar to scanf statement of C language
The fourth line will display the Name you entered.
Comments
Post a Comment