Sometimes, dealing with command line parameters is pretty useful for configuration scripts. After some minutes banging my head against the wall, I found the solution for that. Here are example scripts for Python and Shell script:

In python

user@localhost:~$ cat command_line.py
import getopt
import sys

def start(argv):
opts, args = getopt.getopt( argv[ 1: ], "n:a", ("name=", "age=" ))
print "Arguments: ", opts
for opt,arg in opts:
if opt in ( "-n", "--name" ):
print "The user typed his name: %s" %arg
elif opt in ( "-a", "--age" ):
print "The user typed his age: %s" %arg

start(sys.argv)
user@localhost:~$
user@localhost:~$
user@localhost:~$ python command_line.py --name="Leo" --age=26
Arguments: [('--name', 'Leo'), ('--age', '27')]
The user typed his name: Leo
The user typed his age: 27
user@localhost:~$



In Shell script
user@localhost:~$ cat command_line.sh
#!/bin/bash

NAME=""
AGE=""

if [ $# -gt 0 ]; then
while [ $# -gt 0 ];do
if [ "$1" == "--name" ];then
if [ -n "$2" ]; then
NAME=$2
fi
shift
shift
elif [ "$1" == "--age" ]; then
if [ -n "$2" ]; then
AGE=$2
fi
shift
shift
else
echo "Unknown option: $1"
shift
fi
done
fi

echo -e "NAME: $NAME\nAGE: $AGE"

user@localhost:~$
user@localhost:~$
user@localhost:~$ bash command_line.sh --name leo --age 27 --wrong
Unknown option: --wrong
NAME: leo
AGE: 27
user@localhost:~$
user@localhost:~$ bash command_line.sh --name leo --age
NAME: leo
AGE: