Unable to source file in my script

Hi,

ls -ltrq res.file
-rwxrwxr-x   1 ora   install    4278 Nov 30 07:19 res.file
$ more test.sh
source res.file
$ ./test.sh
./test.sh[1]: .: res.file: cannot open [No such file or directory]
$ id
uid=600000014(ora) gid=63855(install)
uname -a
SunOS mymac 5.11 11.2 sun4v sparc sun4v

The same thing works fine on a Linux box.

Can you tell me why i m getting No such file or directory error when the file is in the same directory?

Without deeper analysis - check for DOS <CR> (\r, ^M, 0x0D) line terminators.

Check the PATH environment variable.

I don't see any special characters in the file.

echo $PATH
/usr/bin:/usr/sbin
$ cat -ev res.file
#By Myself$
$
# Environment Variables$
TIMESTAMP=`date "+%Y%h%d_at_TIME_%H_%M_%S"`$

Can you please suggest ?

Either change the PATH to:

PATH=/usr/bin:/usr/sbin:.

or
change the script to:

source ./res.file
1 Like

Hello mohtashims,

Just a small thing here, did you try to get it in a new session, try to login to the server by a new session and have a try then.

EDIT: By seeing your error closely it may be an issue with complete path for source res.file , so is it the case like your script is in a different path and then you have to provide complete path for it, could you please give it a try and let us know then how it goes.

Thanks,
R. Singh

Even though i did not see any special M ^M characters using the cat -ev res.file i did dos2unix res.file res.file and that seems to have resolved the error.

But, any explanation please ??

By editing your file in Microsoft Notepad you have inserted carriage return characters which will not be seen in terminal but will be taken as literal parts of filenames, etc by the shell.

The actual error was most likely "can't find myfile.sh\r" or the like.