Lock file creates with '?'

Hi,

I am trying to create a lock file with the following code but for some reason after file is created it has
wrong name "PASP?.lock??"

Please let us know how to get rid of these '??' from file name and from where they are coming?

#!/bin/ksh
################################################################################
PGM_NAME='PASP'
LOCKFILE=/tmp/${PGM_NAME}.lock
################################################################################

if [ -e $LOCKFILE ] ; then 

    echo "data file does exist"

else 
   touch ${LOCKFILE}
   echo "new data file created"

fi

Thanks
Sandy

Are you editing your scripts with Microsoft Notepad?

This will fill the file with carriage returns at the end of each line, which most shells will take as literal characters.

tr -d '\r' < windowstextfile > unixtextfile

Please use code tags for multiple lines, not icode.

1 Like

You haven't given us much to help with this, but as a wild guess I'd say you edited your script with something that adds a carriage return before the newline at the end of each line. To verify, try:

od -c NameOfFileContainingScript

and look for occurrences of the string \r in the output.

1 Like

thanks for reply. I have used Notepad++ editor. It does support shell scripting.
Which is the best editor for Shell Scripting?

Both of you are right , there are carriage returns in my scripts. I have removed them and it worked. Thanks for help.

vi, emacs, ex, ed, or any other editor of your choice that was intended for use on systems other than Windows.

1 Like

You can use Notepad++ to edit files destined for a UNIX system, just make sure to set the line ending preference appropriately.

Just use vi.