Computing.Net > Forums > Unix > function with argument

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

function with argument

Reply to Message Icon

Name: sivakarthik
Date: October 3, 2005 at 09:17:25 Pacific
OS: Unix
CPU/Ram: 512
Comment:

Hi,

logMsg(data)
{
now=`date '[+%d/%m/%y %H:%M:%S] '`
echo $now
}
logMsg("Welcome")


The above code give the following error

"Syntax error at line 12 : `(' is not expected."

Can you help me.

Thanks
Siva

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: October 3, 2005 at 11:08:04 Pacific
Reply:

Hi:

You are not understanding how functions work in the shell and the syntax:

logMsg ()
{
echo "argument 1 is: $1"
now=`date '+%d/%m/%y %H:%M:%S'`
#now=`date '[+%d/%m/%y %H:%M:%S] '`
echo $now
}

logMsg "Welcome"
# end script

Also, the date command doesn't like [].


0

Response Number 2
Name: Jim Boothe
Date: October 3, 2005 at 11:08:09 Pacific
Reply:

logMsg()
{
now=`date "+%d/%m/%y %H:%M:%S"`
echo $now
echo "Passed parameter1: $1"
echo "Passed parameter2: $2"
}
logMsg Welcome Partner


Passed parameter1: Welcome
Passed parameter2: Partner


0

Response Number 3
Name: Jim Boothe
Date: October 3, 2005 at 11:09:32 Pacific
Reply:

Oops, posted at same time. nails had it covered.


0

Response Number 4
Name: nails
Date: October 3, 2005 at 11:24:29 Pacific
Reply:

Jim:

That OK. I don't mind someone keeping me straight -)


0

Response Number 5
Name: sivakarthik
Date: October 4, 2005 at 06:48:30 Pacific
Reply:

Thanks Nails and Jim, I'm a Unix starter :)

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva



0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: function with argument

Can't compile Stevens code from apu www.computing.net/answers/unix/cant-compile-stevens-code-from-apu/5931.html

Copy everything from one Hard disk to an www.computing.net/answers/unix/copy-everything-from-one-hard-disk-to-an/1973.html

Shell Scripting -DateTime Manipulat www.computing.net/answers/unix/shell-scripting-datetime-manipulat/6010.html