Unable to set variables in Linux script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unable to set variables in Linux script
# 1  
Old 03-09-2011
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.
Code:
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.
Code:
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:
Code:
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.

Last edited by Franklin52; 03-09-2011 at 04:29 AM.. Reason: Please use code tags, thank you
# 2  
Old 03-09-2011
Can you try as below..
Code:
#!/bin/ksh
script_dir="/home/abap/scripts"
log_dir="$script_dir/Logs"
BATCH_ID=0
FileNM=$1
filepath=$2

# 3  
Old 03-09-2011
michael,

I tried but still I see same substitution happening.

Thanks
smr.ryl
# 4  
Old 03-09-2011
Remove the CRs (carriage returns) from the ends of the lines.

(Did you write the script in a Windows editor?)
# 5  
Old 03-10-2011
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 :
Code:
`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:
Code:
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.

Last edited by Franklin52; 03-10-2011 at 03:42 AM.. Reason: Please use code tags
# 6  
Old 03-10-2011
Give -s to sqlplus command and try..
Code:
sqlplus -s ...

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Unable to set static ip address

Hi All, Am using centos 7 in my vmware workstatio with the bridged network. when run the ifconfig cmd its not at all showing the ip address and pls advise how to set static ip address in my linux box. (1 Reply)
Discussion started by: sarathkumar s
1 Replies

2. Shell Programming and Scripting

<< Environmental Variables are not set when script completes >>

Hi Team, I have a wrapper script which i have pasted below, it internally calls one python script to generate Environmental in a file called /home/oracle/myenv.sh, when i execute this script via wrapper script, its not reflecting in my current session, still showing old env variables. any... (2 Replies)
Discussion started by: kamauv234
2 Replies

3. Shell Programming and Scripting

Unable to set my PATH variable

Hello All, Hope you can understand my problem from the below code. $ cat ~/.profile PS1=`whoami`@`hostname`':$PWD $ ' export PATH="$PATH:.:/logarchive/utility/util:/usr/sbin:" $ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:.:/usr/sbin: $ echo $SHELL /usr/bin/ksh ... (6 Replies)
Discussion started by: sathyaonnuix
6 Replies

4. Shell Programming and Scripting

Unable to change environment variables in bash script

Hello! For the moment some settings in my .bashrc contain the password of my company's firewall, which is not a good idea. I would like to use the string "PASSWORD" set in .bashrc and a script that changes all appearances of "PASSWORD" in the environment variables by the actual password (which... (4 Replies)
Discussion started by: markolopa
4 Replies

5. Shell Programming and Scripting

Unable to set a data to array

Hi All, Iam trying to set the value to the array... Still its not happening Following is the code: #!/usr/bin/ksh filenames="x"; filenames="y"; echo $filenames; echo $filenames; O/P: x x Iam expecting (2 Replies)
Discussion started by: kiranlalka
2 Replies

6. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

7. Linux

DNS unable to set up!!

Hi Experts, I am a newbie like in Linux world, practising Fedora Linux on VMWare but DNS is never set up: Below are my conf files: 1. named.conf options { directory "/var/named"; /* * If there is a firewall between you and nameservers you want * to talk... (4 Replies)
Discussion started by: vikasdh
4 Replies

8. Shell Programming and Scripting

Ksh script - Design ? - Search file and set variables

Hi - I'm trying to think of a clever way to write a shell script (trying to stay w/ ksh as that's what I know the best...) that will resolve the following problem: Problem - On a daily basis I have to email folks who are on-call to remind them. I was hoping to script this out so I could have... (9 Replies)
Discussion started by: littlefrog
9 Replies

9. UNIX for Dummies Questions & Answers

Using Variables to Set Other Variables

I have a script that I'm trying to shorten (below) by removing repetitive code. if ] then commodity_ndm_done=Y fi if ] then customer_ndm_done=Y fi if ] then department_ndm_done=Y fi if ] then division_ndm_done=Y fi (3 Replies)
Discussion started by: superdelic
3 Replies

10. UNIX for Dummies Questions & Answers

how to set up linux environment variables?

Hi I'm using Linux, in the directory /root/my there is a.out. but when I try to run it , the shell indicate "bash:a.out: command not found" but I AM working in this directory. if I use "./a.out" , it works perfectly. can any body tell me how to do a permanent set up so that I can use... (5 Replies)
Discussion started by: dell9
5 Replies
Login or Register to Ask a Question