Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with function in shell

Status
Not open for further replies.

raypru

Technical User
Apr 9, 2002
26
GB
This is my script called dbfunctions.ksh:

function LOGF
{
tstamp=`date '+%d/%m/%y %X'`
echo "$tstamp ${1}" >> $LOG
return 0
}
LOG=test.log

First I pass the command set -x

but when I run the script the following error occurs. I cannot see anything wrong.
. ./dbfunctions.ksh
+ . ./dbfunctions.ksh
++ $'\r'
: command not found
++ $'\r'
: command not found
'bash: ./dbfunctions.ksh: line 17: syntax error near unexpected token `{
'bash: ./dbfunctions.ksh: line 17: `{
 
I don't have any problems, are running pdksh or the real AT&T ksh?
 
Hi,

in your output you have got this line:
++ $'\r'

Where does \r come from?
I guess your file dbfunctions.ksh is in DOS format, with a CR, aka \r, aka ^M, aka 0x0d, at the end of the lines.
So please check this.

Btw, you have an error in line 17, but your script is shorter.
I presume you copied a part of it only?

hope this helps
 
Also notice that your script is designed for ksh, but you are running it from bash.

Annihilannic.
 
Hi everyone who responded thanks for your input. It looks like the problem was caused by my developing this shell on a Unix box at work, FTPing to my desktop, emailing to my home and copying to my home Linux server. This long way of getting this script from work to home has interferred with the format. Hoinz commented about the \r being a DOS format CR so I manually typed in the text and everything worked OK.
 
...actually it would be quite helpful to know how to get scripts like this from work to home without the format being changed or how can I convert the format once I have got the script to my home.
 
Either FTP in binary mode or zip or tarball it and it should turn out right.

Note that you need to use binary mode to transfer the zip or tarball as well.

Annihilannic.
 
Just proves what I've always said. Windows is the root of all Evil.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top