I am using the following kind of bash code. I store some information within log file which name is defined in the bash script.
LOGNAME="/tmp/ETH"
LOG_FILE="${LOGNAME}.log"
function exit_error()
{
case "$1" in
100 )
echo "Bad arguments supplied - Enter help"
echo "Bad arguments supplied - Enter help" >> "${LOG_FILE}"
;;
101 )
echo "Illegal number of parameters"
echo "Illegal number of parameters" >> "${LOG_FILE}"
;;
* )
;;
esac
exit 1;
}
function current_status()
{
INT_STATUS=$(cat /sys/class/net/eth1/operstate)
echo "status : $INT_STATUS"
echo "status : $INT_STATUS" >> "${LOG_FILE}"
}
function connect_eth()
{
...
}
...
case "$1" in
current_status )
if [ "$#" -ne 1 ]
then
exit_error 101
else
current_status
fi
;;
connect_eth )
if [ "$#" -ne 1 ]
then
exit_error 101
else
connect_eth
fi
;;
read_MAC_addr )
if [ "$#" -ne 1 ]
then
exit_error 101
else
read_MAC_addr
fi
;;
read_IP_addr )
if [ "$#" -ne 1 ]
then
exit_error 101
else
read_IP_addr
fi
;;
* )
exit_error 100
;;
esac
exit 0;
I would like to modify the script in order to use the specified log name if no other log name is specified as last parameter. However, I would like to keep my "exit_error 101" in switch case which is based on the number of parameters passed to the script. Is there a way to do that ? Because I can not modify the $# variable.