1

I am trying to extract filenames with .url extension using $name =~ s/\.url$//;. However, some of the names contain an exclamation mark just before the extension, e.g.:

"for example-this!.url" "and-something-else!.url"

This causes perl to emit an error and stop running:

bash: !.url": event not found

Is there a way to overcome this problem? Below shows part of the relevant code that I am using:

foreach my $f (@ARGV) {
 my (undef, $dir, $name) = File::Spec->splitpath($f);
 $name =~ s/\.url$//;
devnull
  • 118,548
  • 33
  • 236
  • 227
Question Overflow
  • 10,925
  • 18
  • 72
  • 110

2 Answers2

2

The error that you're getting happens when history expansion is enabled (which is the default).

In order to disable, do

set +o histexpand

on the command line.

devnull
  • 118,548
  • 33
  • 236
  • 227
1

The error is not from perl but from the bash. You may want to store the filenames in a file and read them from there. Note that this problem only occurs when the bash is parsing your command line input. When the script reads filenames from a file, pipe, etc. there won't be any problem.

tauli
  • 1,420
  • 8
  • 13