2

I am running a perl script which execute the shell command as :

system ("bsub xyz +OPTIONS_GATE=$GATE")

here $GATE is my environment variable. When I execute the script. It gives the error

"No arguments supplied for option group OPTIONS_GATE instance". 

How to deal with this issue. Thanks in advance

1
  • 3
    Always use use strict; use warnings;. If finds many errors, including this one. Commented Sep 25, 2014 at 12:10

1 Answer 1

8

$GATE in a double quoted string will be considered a Perl variable. If you want to use an environment variable, you can use the %ENV hash:

system ("bsub xyz +OPTIONS_GATE=$ENV{GATE}")

Alternatively, you can escape the dollar sign so Perl does not treat $GATE as a Perl variable:

system ("bsub xyz +OPTIONS_GATE=\$GATE")

Or use a single quoted string, which does not interpolate variables:

system ('bsub xyz +OPTIONS_GATE=$GATE')

Note that if you had used

use strict;
use warnings;

It would have told you about this error. strict would have said:

Global symbol "$GATE" requires explicit package name
Execution of script.pl aborted due to compilation errors.

And warnings would have said:

Name "main::GATE" used only once: possible typo at script.pl line 12.
Use of uninitialized value $GATE in string at script.pl line 12.

When you do not use use strict; use warnings; your errors are not removed, they are only hidden from you, so that they are harder to find. Therefore, always use these two pragmas.

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

1 Comment

The shell will still interpolate without escaping, so the best is actually system('bsub xyz +OPTIONS_GATE="$GATE"') or system('bsub', 'xyz', '+OPTIONS_GATE='.$ENV{$GATE})

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.