Let's create a better version of our hello.sh script. We will let the user input his/her name and then we will greet the user; create a script named greet.sh with the following lines:
elliot@ubuntu-linux:~$ cat greet.sh
#!/bin/bash
echo "Please enter your name:"
read name
echo "Hello $name!"
Now make the script executable and then run it:
elliot@ubuntu-linux:~$ chmod a+x greet.sh
elliot@ubuntu-linux:~$ ./greet.sh
Please enter your name:
When you run the script, it will prompt you to enter your name; I entered Elliot as my name:
elliot@ubuntu-linux:~$ ./greet.sh
Please enter your name:
Elliot
Hello Elliot!
The script greeted me with "Hello Elliot!". We used the read command to get the user input, and notice in the echo statement, we used a dollar sign, $, to print the value of the variable name.
Let's create another script that reads a filename from the user and then outputs the size of the file in bytes; we will name our script size...