Problem while concatenating variables in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem while concatenating variables in shell script
# 1  
Old 02-23-2011
Problem while concatenating variables in shell script

Hi folks,

I am facing problem when I concat variables with the string.

Value for 'JDBC_CLASSES' variable looks malformed (/classes12.zip2.0KAGES)

But, my expected result for 'JDBC_CLASSES' is
/opt/API-R111/PACKAGES/jdbc/ORACLE9.2.0/classes12.zip

Am I missing anything here?

My Script :
-------------
Code:
#!/bin/sh
echo "== SET ENVIRONMENT VARIABLES =="
export PACK_HOME=/opt/API-R111/PACKAGES
export JDBC_VER=ORACLE9.2.0
export JDBC_CLASSES=${PACK_HOME}/"jdbc/"${JDBC_VER}/"classes12.zip"
echo $PACK_HOME
echo $JDBC_CLASSES

jmc: added code tags
Output:
--------
[weblogic@localhost admin]$ sh setenv.sh
== SET ENVIRONMENT VARIABLES ==
/opt/API-R111/PACKAGES
/classes12.zip2.0KAGES

Any help on this is highly appreciable.

Regards,
Adhil

Last edited by jim mcnamara; 02-23-2011 at 05:19 PM.. Reason: code tags
# 2  
Old 02-23-2011
First off you realize you have to source this, not run it, right? You do that by running . filename in your shell. Actually executing it will be pointless because it will get its own, separate copy of the environment variables to fiddle with, leaving yours alone.

So remove the #! line, it won't do anything.

Next, properly quote everything.

Next, split the export and = statements since some shells throw up when you combine them.

How does this work?
Code:
echo "== SET ENVIRONMENT VARIABLES =="
PACK_HOME="/opt/API-R111/PACKAGES"
export PACK_HOME
JDBC_VER="ORACLE9.2.0"
export JDBC_VER
JDBC_CLASSES="${PACK_HOME}/jdbc/${JDBC_VER}/classes12.zip"
export JDBC_CLASSES
echo "${PACK_HOME}"
echo "${JDBC_CLASSES}"

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 02-24-2011
Maybe the script has been edited with a Microsoft editor and the strings contain spurious carriage-return characters.

Please post the output from this command which is designed to make line terminators visible:
Code:
sed -n l setenv.sh

When viewed like this a normal unix text file will have a "$" at the end of each line and no other control characters.
This User Gave Thanks to methyl For This Post:
# 4  
Old 02-24-2011
Try splitting your export command and variable setup in different lines, what do you get with this :


Code:
echo "== SET ENVIRONMENT VARIABLES =="

PACK_HOME=/opt/API-R111/PACKAGES
export PACK_HOME

JDBC_VER=ORACLE9.2.0
export JDBC_VER

JDBC_CLASSES="${PACK_HOME}/jdbc/${JDBC_VER}/classes12.zip"
export JDBC_CLASSES

echo $PACK_HOME
echo $JDBC_CLASSES

???

Code:
env | egrep -e 'JDBC|PACK'

# 5  
Old 02-24-2011
Changing ctsgnb to Adhil:
Adhril, please follow the instructions provided by Corona688:
Quote:
First off you realize you have to source this, not run it, right? You do that by running . filename in your shell.
Quote:
Next, properly quote everything.

Last edited by Shell_Life; 02-24-2011 at 01:46 PM..
# 6  
Old 02-24-2011
@Shell Life ,

Oooops, i just realized that Corona already suggested to split the export/assignation into 2 lines.

But in fact i don't have any problem, it is not me who is asking questions about how to source environment variable : it is Adhil

Smilie
# 7  
Old 02-24-2011
ctsgnb, I am really sorry for the confusion. Smilie
I do apologize.
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenating two mutiline variables in a bash

Hi All, I am having a situation where am capturing results in two variables from an xml file. However, I am looking to print those two variables with pipe in between them and these variable are multi-line. This is how my 1st variable looks like: 20181225010 20190224010 20190224010... (8 Replies)
Discussion started by: svks1985
8 Replies

2. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

3. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. Shell Programming and Scripting

Problem in Global variables in shell script

hi, i have a shell script which calls another shell which in turn calls another shell script. Main_shell_script.sh echo "In Main_shell_script.sh" FILENAME="original.txt" # LINE 1 DST_FILENAME=$FILENAME # LINE 2 echo "FILENAME = {$FILENAME}" echo "DST_FILENAME =... (3 Replies)
Discussion started by: Little
3 Replies

5. Shell Programming and Scripting

Concatenating fixed length lines in shell script

I have a peculiar file with record format like given below. Each line is wrapped to next lines after certain number of characters. I want to concatenate all wrapped lines into 1. Input:(wrapped after 10 columns) This is li ne1 This is li ne2 and this line is too lo ng Shortline ... (8 Replies)
Discussion started by: kmanyam
8 Replies

6. Shell Programming and Scripting

bash -- concatenating values from variables

Hi This is a simple one but I got a lost in translation when doing. What I want to do, given both variables in the example below, to get one value at the time from both variables, for example: 1:a 2:b etc... I need to get this in bash scripting code: varas="1 2 3 4" varbs="a b c d"... (4 Replies)
Discussion started by: ranmanh
4 Replies

7. Red Hat

Concatenating variables

Hi all, I'm trying to do a very simple script, as you can see as follow: #!/bin/bash #Valorizzazione Token presenti nel file di properties var_path_weblogic="`cat weblogic.properties | grep "dir_wl" | /usr/xpg4/bin/awk '{print $3}'`" var_ip_address="`cat... (5 Replies)
Discussion started by: idro
5 Replies

8. Shell Programming and Scripting

problem accessing Multiple Variables from C Program to a Shell script

program name--test #!/bin/bash output1=`/home/user/a.c` output2=`/home/user/a.c` k=`$output1 + 1` m=`$output2 + 1` echo $k echo $m --------------------------------------------------------------------------- prgram name--a.c #include<stdio.h> int main() (1 Reply)
Discussion started by: sameworld1980
1 Replies

9. Shell Programming and Scripting

Concatenating Different # of Variables

Hi, I'm quite new at unix and was wondering if anyone could help me with this. I have 2 arrays: eg. STAT=online, STAT=offline, STAT=online WWN=xxxx1, WWN=xxxx2, WWN=xxxx3 I got these information from a script using fcinfo hba-port that runs through a loop. Now, I want to store... (2 Replies)
Discussion started by: jake_won
2 Replies

10. Shell Programming and Scripting

Concatenating Variables

FILE_DATE=$(date +"%Y%m%d_%H%M")_ FILE_PREFIX=${FILE_DATE} echo $FILE_PREFIX JS_LOG_DIR="E:\DecisionStream Jobs\Invoice Balance Fact Jobs" echo $JS_LOG_DIR --This is where the problem surfaces. The last line of this script does a rsh to an NT machine and one of the parameters is the... (2 Replies)
Discussion started by: photh
2 Replies
Login or Register to Ask a Question