next up previous
Next: Conditional Statements Up: The Shell Script Previous: Variables

Command Line Parameters

When shell script is started, variables $0 to $9 are set to values of parameters passed from the command line.

Example: Create a script file test.sh by using vi editor:
vi test.sh
#!/bin/sh
echo Parameter 1: $1
echo Parameter 2: $2

Save the file, allow execution by changing the permission and execute it with two input parameters hello and world:
./test.sh hello world

The following output will be displayed:
Parameter 1: hello
Parameter 2: world



Instructional Support Group 2008-08-05