0

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 ?

4
  • This is strange. Can you just print $1 at the beginning and/or execute the shell script with sh -x? That will give you hints. Commented Aug 18, 2011 at 8:08
  • How do you know that no parameter is being passed? Do you get an error message? In that case, can you post it? In case your exportcli program tries to report an error on stdout instead of stderr, can you remove the >/dev/null? Commented Aug 18, 2011 at 8:18
  • Useing -x I got the following result ++ . /mnt/.kumara/automation/exportcli.cfg +++ TFA_ST=1312464957000...<all the remaining substitutions> +++ 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>' ++ echo But echo $1 results in a blank Commented Aug 18, 2011 at 9:50
  • It would be better if you used the "edit" button underneath your main post, that allows better formatting than the comments do. Commented Aug 18, 2011 at 10:06

1 Answer 1

1

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).

Sign up to request clarification or add additional context in comments.

6 Comments

Could you update your question with this output, and put it in a code block? That would make it easier to read.
But if I parse this correctly, it seems that EXPORT_FLT_2 is defined in the exportcli.cfg file, as @qiaomuf and myself touched on in his answer.
I tried using all the tricks of debugging you mentined in your answer. However even tough I can see the variable actually being defined in -x the echo $1 results in a blank, when I run sh -x $./export.sh "$EXPORT_FLT_2" . My guess is that there might be some kind of an error in the definition in the exportcli.cfg file...but not sure :(
++ . /mnt/.kumara/automation/exportcli.cfg +++ TFA_ST=1312464957000...<all the remaining substitutions> +++ EXPORT_FLT_2='<ngc_filter_configuration><ngc_filters><ngc_filter><ngc_filter_ope‌​rator 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>' ++ echo
Did you see the update to my answer? EXPORT_FTL_2 is apparently not defined in the shell you use to start your export.sh script. So sticking $EXPORT_FTL_2 on the command line will expand it to "" before your script starts, and $1 will be empty. Use EXPORT_FTL_2 without the $ on the command line, and use the ${!1} trick in your script to tell bash that there is a level of indirection there.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.