2

I am using Getpt::Long to take the arguments from the command line and assign them to their respective variables. But, I am getting errors when I am printing it. The code and the error is as follows:

#!usr/bin/perl

use strict;
use warnings;
use Getopt::Long;

GetOptions(
    "mount_path=s" => \my $old_path,
    "var=s"        => \my $var,
    "log_path=s"   => \my $log_path,
) or die "Error in input variables\n";

print <<"END_INPUTS";
 These are your inputs: 
 old_path= $old_path 
 var = $var 
 log_path=$log_path 
 Press enter twice if all looks GOOD 
 *********************************************************
END_INPUTS

The command line arguments are as follows:

 perl getvar.pl --mount_path=/var/sslvpn --var=7.0.0.2_va-SSLVPN-!7.0.0.2.16sv+.jpn-05!j+g_554863- --log_path=log.txt  

I am getting the following error while running this

-bash: !7: event not found
toolic
  • 57,801
  • 17
  • 75
  • 117
deep
  • 686
  • 4
  • 17
  • 33

1 Answers1

8

This is not a Perl problem. The bash shell is processing ! as a special character. You'll have to quote that argument.

 --var='7.0.0.2_va-SSLVPN-!7.0.0.2.16sv+.jpn-05!j+g_554863-' 

You can tell that it's a bash problem and not a Perl problem because the message says it's from bash:

-bash: !7: event not found

Bash never even gets to the part where it runs your program.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152