Hiso
1
Hi All,
What is the problem with the following script:
function mmdd
{
dd=$2
case $1 in
"Jan") mm=01;;
"Feb") mm=02;;
"Mar") mm=03;;
"Apr") mm=04;;
"May") mm=05;;
"Jun") mm=06;;
"Jul") mm=07;;
"Aug") mm=08;;
"Sep") mm=09;;
"Oct") mm=10;;
"Nov") mm=11;;
"Dec") mm=12;;
*) echo "error"
exit ;;
esac
echo ${mm}${dd}
}
and then i call
var1="Sep 12"
var3=$(mmdd $var1)
I get the following error:
-bash: mmdd: command not found
it will work fine in ksh.. are you working with bash??
The call of a function must be placed after the function definition.
Regards
rikxik
4
It works fine in bash:
$ cat fn
#!/usr/bin/bash
function mmdd
{
dd=$2
case $1 in
"Jan") mm=01;;
"Feb") mm=02;;
"Mar") mm=03;;
"Apr") mm=04;;
"May") mm=05;;
"Jun") mm=06;;
"Jul") mm=07;;
"Aug") mm=08;;
"Sep") mm=09;;
"Oct") mm=10;;
"Nov") mm=11;;
"Dec") mm=12;;
*) echo "error"
exit ;;
esac
echo ${mm}${dd}
}
#and then i call
var1="Sep 12"
var3=$(mmdd $var1)
echo "$var3"
$
$ fn
0912