tr command fail to work in script

Hi,
I has the following command in the script. This command works fine if I execute on command prompt. If I run the script, this is not working as expected (deleting CR).

tr -d "\015" < ${FilePath}/${FileName} > ${FilePath}/${File_Prefix}.csv
     I could not figure out whats wrong. Please let me know whats wrong in this.

Thanks & Regards
Kavuri

Hi.

Did you export the variables FileName and FilePath prior to running the script?

Hi Scott,
When I run through command line I had substituted the variables.

         When I am running the same command from script, I had defined the variable names at the beginning of the script.

FilePath=/dir_path/
FileName=file1.csv

Thanks
Kavuri

What about File_Prefix?

I did defined File_Prefix as well. just as an example I had given some dummy values.

Thanks
Kavuri

Assuming that your original file (which I shall call "filename") is a MSDOS text file with a carriage-return character in every record.
What is the output from this sequence of commands both from the command prompt and from a shell script. I'm assuming that your shell is not "csh" or "tcsh".
The "sed -n l" command just makes control codes visible.

filename="insert_the_name_of_your_original_file"
echo "Shell is:"
echo "${SHELL}"
echo "Original file"
head -1 "${filename}" | sed -n l
echo "Conversion 1"
head -1 "${filename}" |tr -d "\015" | sed -n l
echo "Conversion 2"
head -1 "${filename}" |tr -d '\015' | sed -n l
echo "Conversion 3"
head -1 "${filename}" |tr -d "\r" | sed -n l

Hi,
I see these DOS characters are not consistantly in all the lines. They appear in some lines only. As the below code will check for the CR in first line only, it could not help us in figuring out the issue.

        I had seen some more characters like vt \(vertical tab - 0x0b\) etc.. as well. 

        I got the codes to remove all these DOS characters but it is working only sometimes.

       I think we need to check for the previous command execution status before the next command executes in the script. Can someone explain more on this?

Thanks
Kavuri