0
#!/bin/bash
export IPV6=$1
expanded_ipv6_addr=`perl -e 'require "/usr/bin/ipv6_helper.pm"; $expand_ipv6=expand_ipv6_addr($ENV{IPV6});print $expand_ipv6'`

I don't want to export the $IPV6 variable, so I am looking any other way to do this.

2
  • 1
    Why don't you write a Perl script expand_ipv6_addr that expands addresses given as command line arguments? Commented Mar 10, 2015 at 12:21
  • Why do you have a problem with passing it to perl via its environment? Commented Mar 10, 2015 at 15:19

2 Answers 2

2

Grab the value from @ARGV:

expanded_ipv6_addr=$(
  perl -e '
    require "/usr/bin/ipv6_helper.pm"; 
    print expand_ipv6_addr(shift)
  ' "$IPV6"
)
Sign up to request clarification or add additional context in comments.

Comments

-1

Instead of exporting $1 into an environment variable you could use it again later and escape the perl code.

The following worked for me with a stubbed out version of /usr/bin/ipv6_helper.pm

#!/bin/bash
IPV6=$1
expanded_ipv6_addri=`perl -e "
   require \"/usr/bin/ipv6_helper.pm\";
   \\$expand_ipv6 = expand_ipv6_addr($IPV6);
   print \\$expand_ipv6
"`

2 Comments

Doesn't work. ./expand 2001:0db8:85a3:0000:0000:8a2e:0370:7334 gives a number of syntax errors because expand_ipv6_addr(2001:0db8:85a3:0000:0000:8a2e:0370:7334) is not valid Perl code.
You might be tempted to add quotes, that would only be a partial fix because that would allow ./expand '".malicious()."'. Generating code is an awful idea. Instead, you should use a parameter, the environment (which the OP forbade for unknown reasons), STDIN, etc.

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.