Unable to set variables in Linux script

Hi,

I am pretty new in writing shell script on LINUX, I tried to write the script just like KSH on HP unix but it seems nothing is working. Even assigning variables seems to be not working as KSH on HP unix. Please help in resolving the issues I am facing on LINUX. I have declared variables for paths and some constant values like below.

script_dir=/home/abap/scripts
log_dir=$script_dir/Logs
BATCH_ID=0
FileNM="$1"
filepath="$2"

I even tried putting values in between single and double qoutes, but it is substituting the values like below.

script_dir=$'/home/abap/scripts\r'
log_dir=$'/home/abap/scripts/Logs\r'
BATCH_ID=$'0\r'
FileNM=$'abcdef.txt\r'
filepath=$'/home/srcfiles/mon/\r'

I don't know why it is assigning a '$' in front and \r' at the end for all the values. I tried using bash,ksh,sh.............but all are behaving same way. Please let me know if there is other way I should be doing this.

output of debugger mode:

FileNm="$1"
+ FileNm=$'ERO140I.I.ICGFLEX.20101111\r'
filepath="$2"
+ filepath=$'/home/nr49398/scripts/\r'
BTCH_ID=0
+ BTCH_ID=$'0\r'

Appreciate you help.

Can you try as below..

#!/bin/ksh
script_dir="/home/abap/scripts"
log_dir="$script_dir/Logs"
BATCH_ID=0
FileNM=$1
filepath=$2

michael,

I tried but still I see same substitution happening.

Thanks
smr.ryl

Remove the CRs (carriage returns) from the ends of the lines.

(Did you write the script in a Windows editor?)

Yes Johnson I have written this script in windows editor and then moved on to linux server. Thanks Johnson!! I removed carriage returns and it worked.

Also I am trying to spool data from oracle to a file, but along with data sql query and other stuff is also spooling, can you please help me to spool only data into the file.

my script has :

`sqlplus $crdn<<END >$sfile
set def off;
set echo off
SPOOL $sqfile
set pagesize 10  head off linesize 165
select CTRL_FILE_NM||' '||LND_TBL_NM||' '||FEED_CD||' '||DOWNLOAD_DIR from DIM_INV_DETL where FEED_NM='${feednm}';
SPOOL OFF
exit;
END`

spool file:

SQL> set pagesize 10  head off linesize 165
SQL> select CTRL_FILE_NM||' '||LND_TBL_NM||' '||FEED_CD||' '||DOWNLOAD_DIR from DIM_INV_DETL where FEED_NM='ERO140I.P.ICGFLEX';
CNTRL2.CTL LND_PP_2 ERO140I /opt/rectify/fasttrac/AML/transform/AGU065D/                                                                                     
SQL> SPOOL OFF

Thanks in advance.

Give -s to sqlplus command and try..

sqlplus -s ...