Browsing around...
News  News Links  Links Blog  Blog Italiano  Español 
09 - Data input in the bash


During the execution of a script you can request to the user to insert some data through the read command. This command, similarly to scanf in C, won't visualize any new message, but will wait for the user to insert a variable and press the Enter key. This is an example:

# This script requests to the user an input from the keyboard and then visualizes it.

# The -n options avoids to wrap.
echo -n "Write your name [Enter]: "
read user_name
echo "Hello $user_name!"


Command line parameters
The command line parameters are variables which are passed to the script when it is launched from the command line. Inside the script these parameters can be referred as following:

$#It contains the total number of passed parameters
$num_paramContains the value of the num_param parameter
$?It contains the result of the last executed command
$0Contains the name of the script
$*Contains all the ordered parameters
"[email protected]"Contains all the ordered parameters with double quotes

This is an example:


# This script shows how to recall in the code the values
# passed to the script as command line parameters

echo "The name of this script is: $0"
echo "You inserted $# parameters, which in order are: $*"
echo "The first one is: $1"
echo "The second one is: $2"
echo "The last executed command returned: $?"


Fatal error: Call to undefined function sqlite_open() in /membri/giacobbe85/include/ on line 324