Sunday, December 27, 2009

How to read arguments in shell program

How to read arguments in shell program

#!/bin/sh
for i in $*
do
echo $i
done

$# returns the number of parameters that are passed to a shell script
$? returns the exit code of the last executed command (0 : Successful, 1 or other: Failed)




On executig the above script with any number of command-line arguments it will display all the parameters.

No comments:

Post a Comment