Export command giving Variable Name vs the Value set for the Variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Export command giving Variable Name vs the Value set for the Variable
# 1  
Old 03-31-2006
Export command giving Variable Name vs the Value set for the Variable

I'm having an issue when I export within my program. I'm getting the variable name, not the variable value. I have a configuration file (config.txt) that has the values of the variables set as so:

Code:
set -a
export ARCHIVEPOSourceDir="/interfaces/po/log /interfaces/po/data"
export ARCHIVEPRSourceDir="/interfaces/pr/log /interfaces/pr/data"

Then I have a shell script that I'm passing the configuration file and the interface name to as follows:

./CleanUpFiles.sh -C config.txt -P ARCHIVEPO

and here's the code in CleanUpFile.sh:

Code:
#!/usr/bin/ksh
PROG_NAME=`basename $0`

Usage ()
{
 echo "Usage: $PROG_NAME -C ConfigFile(config.txt) -P ARCHIVE_Interface_Name" 
 exit 1
}

if [ $# -ne 4 ]
then
 Usage
fi

while getopts C:P: Opt
do
    case ${Opt} in
        C) INTERFACE_CONFIG_FILE=${OPTARG}
           ;;	
        P) ARCHIVE_Interface_Name=${OPTARG}
           ;;
        ?) Usage 
    esac
done

. ${INTERFACE_CONFIG_FILE} 

export SOURCEDIR=${ARCHIVE_Interface_Name}SourceDir
echo ${SOURCEDIR}

So I pass ARCHIVEPO as the value for ARCHIVE_Interface_Name parameter to CleanUpFiles.sh. When the program executes: export SOURCEDIR=${ARCHIVE_Interface_Name}SourceDir, my expectation was that it would give back the values, "/interfaces/po/log /interfaces/po/data", but instead I get back "ARCHIVEPOSourceDir". If I hard code the statement as:export SOURCEDIR=${ARCHIVEPOSourceDir}, then I correctly get back the values, "/interfaces/po/log /interfaces/po/data". I need to be able to pass it as a parameter though, because this code is going to be reused by different interfaces. Any suggestions on a way around this?

Thanks,
Les...
# 2  
Old 03-31-2006
Try:
eval export SOURCEDIR=\$${ARCHIVE_Interface_Name}SourceDir
# 3  
Old 04-03-2006
Thank ya Perderabo! That worked!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Export command - variable

Hello, Please see the script found in my computer below. (Ubuntu 14.04) #!/bin/sh export APP_DIR="/home/appname" monitorscript="$APP_DIR""/monitor.sh" ps cax | grep monitor.sh > /dev/null if ; then echo "monitor.sh is running" else "$monitorscript" fi My question is regarding EXPORT... (3 Replies)
Discussion started by: baris35
3 Replies

2. Shell Programming and Scripting

Bash script set command to a variable

Hi, Will following set up work in bash script? I've got errors if assigning following binary command to a variable. But on the other hand, COMMAND="ls" works. Any explanation please? How can I assign binary command to a variable COMMAND then I can just call ${COMMAND}? COMMAND="rsync"... (3 Replies)
Discussion started by: hce
3 Replies

3. Shell Programming and Scripting

Set shell variable from command

shell script has a command inside back quotes in method update_TABLE I need to store the count of number of Rows updated and store it in shell script variable "num" num = 0; Update_TABLE Update_TABLE() { `echo " set verify off feedback off echo off pagesize 0 head off... (4 Replies)
Discussion started by: finder255
4 Replies

4. HP-UX

What is the use of command set -- and set - variable?

Hi, I am using hp unix i want to know the use of the following commands set -- set - variable thanks (4 Replies)
Discussion started by: gomathi
4 Replies

5. Shell Programming and Scripting

Export command variable exporting problem

I have a txt file from which i am assiging a value to a variable using the code in script1 script1.sh export f=$(sed -n "/Freq *=/ s/.*= *//p" ${R_path}/output.txt) echo "$f" --------> this works in script2 ( which executes the script1) eval ./script1.sh if && ; then echo... (1 Reply)
Discussion started by: shashi792
1 Replies

6. Shell Programming and Scripting

set variable to command output

I'm hoping you guys can help me out here. I've been trying different methods to try and get what IW as hoping would be a fairly simple script but has turned into a pain. Bit of background - I am writing a script to check values in certain failes to ensure they are corerct. I'm runnign this on... (2 Replies)
Discussion started by: stuc
2 Replies

7. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

8. Shell Programming and Scripting

How to set mutliple words variable from command line

I'm writing a script (C shell) to search for a pattern in file. For example scriptname pattern file1 file2 filenN I use for loop to loop through arguments argv, and it does the job if all arguments are supplied. However if only one argument is supplied (in that case pattern ) it should ask to... (5 Replies)
Discussion started by: patryk44
5 Replies

9. Shell Programming and Scripting

need sed command to read a path and set to variable

I have a variable called PATH that contains a path example: /Users/rtipton/Desktop/testusers/test I need a sed command to set a variable called USER to the last directory name in that path PATH="/Users/rtipton/Desktop/testusers/test" and from that PATH i need USER to = test I know sed... (4 Replies)
Discussion started by: tret
4 Replies

10. Shell Programming and Scripting

set variable command

Hi all, I want to set a variable in ksh shell (prompt) and echo the value. $ set x=5 $echo $x But it is returning null. Can any one please help. Thanks in advance (1 Reply)
Discussion started by: ammu
1 Replies
Login or Register to Ask a Question