Problem with function in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with function in a script
# 1  
Old 03-23-2009
Problem with function in a script

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

# 2  
Old 03-23-2009
it will work fine in ksh.. are you working with bash??
# 3  
Old 03-23-2009
The call of a function must be placed after the function definition.

Regards
# 4  
Old 03-23-2009
It works fine in bash:

Code:
$ 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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

2. Shell Programming and Scripting

Bash script: problem with a function which use colors

Hello guys :) I've a some issue with a function which use the bash colors in my script. An example : #!/bin/bash set -x log_in(){ host="srv1" remote_files="log/" LOG_FILE="logfile" green='\033]; then color_in_red=("${red}"$2"${none}") echo -e... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

3. Shell Programming and Scripting

Function problem

hey guys, im trying to learn bourne shell atm and I'm having some issues with functions. so heres my code: #!/bin/bash ##functions memory () { free -m } space () { df -h } ip () { (5 Replies)
Discussion started by: hawkfro12
5 Replies

4. Shell Programming and Scripting

Problem while Invoke Shell Script function from Java Program

Hi, I have create a Shell Script, with one function. I want to call the script file in Java Program. It working fine. but the problem is the function in the Shell Script is not executed. Please suggest me, Regards, Nanthagopal A (2 Replies)
Discussion started by: nanthagopal
2 Replies

5. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Shell Programming and Scripting

Calling Function Problem

Hi, I had a scripts which calls two function. One function will call another function, script is working fine but the second function is not calling the first function. Below is the script #!/usr/bin/ksh fun1() { echo $DATETIME >> Test1.ksh return 0 } fun2() { typeset DATETIME=`date... (5 Replies)
Discussion started by: somu_june
5 Replies

8. Shell Programming and Scripting

Problem with a function in a shell script

Hi, I am trying to write a function in the shell script . This function accepts two parameters. It is as following: set_cache(i_SEQ_NAME,I_cache_size) { _sqlplus "BEGIN alter_seq_cache(i_SEQ_NAME, I_cache_size); END;" } _sqlplus is another function and has been working working.... (3 Replies)
Discussion started by: neeto
3 Replies

9. Shell Programming and Scripting

problem, with if condition in function

Hi All, I have a function which reads parameter and gets the value from config file. The entry in the file can be either of two Name=value or Name=value so if the variant is not present it should return me the generic value ie Name without variant. I am first searching for variant in... (4 Replies)
Discussion started by: gurukottur
4 Replies

10. Shell Programming and Scripting

Problem with function script.

Need an extra set of eyes. Can't find function. Can someone help, please. Thanks echo " Is this the correct list of tapes to eject (y/n)?" read option echo $option case $option in y|Y) TAPE_ROUTINE;; ... (3 Replies)
Discussion started by: gzs553
3 Replies
Login or Register to Ask a Question