Sameer Niphadkar
Sameer Niphadkar

Reputation: 61

Bash Shell variable substitution issue

I've defined a variable to be substituted in BASH which looks like this

EXPORT_FLT_2="<ngc_filter_configuration><ngc_filters><ngc_filter>ngc_filter_operator   operator='and'><ngc_filter_term type='ip' value='192.168.175.99'/><ngc_filter_term type='ip' value='72.32.127.138'/></ngc_filter_operator></ngc_filter></ngc_filters></ngc_filter_configuration>";

I now want to use this variable in my shell script which looks like

. /mnt/.kumara/automation/exportcli.cfg
${PA_HOME}/exportcli -v -1:-1:-1:-1 0x1A2B3C4D $TFA_TRACE_FILE $TFA_ip $TFA_ifn   $TFA_ST $TFA_ET "$1" &> /dev/null 
md5sum ${TFA_TRACE_FILE}1.cap | cut -d' ' -f1
rm ${TFA_TRACE_FILE}1.cap

All the variables being used except for "$1" are defined in the exportcli.cfg file Now after executing the script like

$./export.sh "$EXPORT_FLT_2"

Insted of the actual substitution of the variable I see no parameters being passed. Am I missing something here ?

Upvotes: 0

Views: 310

Answers (1)

Peder Klingenberg
Peder Klingenberg

Reputation: 41235

I can't immediately spot the error here, but here's what I'd try.

1: run echo $EXPORT_FLT_2 in your shell to confirm that the variable you've defined is actually defined.

2: Stick echo $1 at various points in your export.sh script in turn, starting at the top. See if the variable gets mangled somewhere.

3: run sh -x export.sh "$EXPORT_FLT_2" to see what the script actually executes on each step.

This should help pinpont more accurately what's happening and where the error originates.

Update

It seems the EXPORT_FLT_2 variable is defined in you config file, not in your shell. Try changing $1 in your script to ${!1} and calling your script as

$ ./export.sh EXPORT_FLT_2

(note, no $ decoration on the variable name).

Upvotes: 1

Related Questions