User input
This page was last updated on September 29, 2013.
Example 1
-
Method 1:
#!/bin/bash echo "This will ask your name and use your name when communicating with you."; echo; echo -n "What is your name? "; read response; echo; echo "Hello, $response!"; echo;
-
Method 2:
#!/bin/bash echo "This will ask your name and use your name when communicating with you."; echo; read -p "What is your name? " response; echo; echo "Hello, $response!"; echo;
Example 2
-
Method 1:
#!/bin/bash echo "This will change to the directory you specify and list its contents."; echo; echo -n "Enter the path to the directory: "; read response; cd $response; echo; echo "The contents of the directory are:"; echo; ls; echo;
-
Method 2:
#!/bin/bash echo "This will change to the directory you specify and list its contents."; echo; read -p "Enter the path to the directory: " response; echo; cd $response; echo "The contents of the directory are:"; echo; ls; echo;
Obligatory Happy Ending
And they all lived happily ever after. The end.

Comment: