0

In my bash_profile I have this:

  function ht() { perl -i -pe 's|<!-- Mirrored from (.*?) -->\n||' "$a" ;}

I want to run ht to do an inline replacement on the file fed to remove an HTML Comment with the HTTrack signature, but when I run this,

ht file.html

I get:

Can't open : No such file or directory.

I suspect this is because of the quotes around my $a which interfere with the perl command being fed. Perhaps it prefixes the " literally to the filename, or something of this nature and overall it becomes the wrong filename.

I tried removing the double quotes around my $a but that doesn't seem to do what I want. How can I resolve this?

8
  • 1
    where is $a defined? I don't see it in your code. Commented May 14, 2012 at 17:31
  • I thought $a was magical bash syntax for the command line arguments fed. I used it in another function to do the same exact thing. Commented May 14, 2012 at 17:32
  • 1
    I think you are referring to $@. Generally quoted, just as you have, "$@". Commented May 14, 2012 at 17:33
  • Nice catch @jwd, I sleazily incorporated that find into my answer... I had decided @meder needed $* but didn't notice she was trying to use "$a" instead. Commented May 14, 2012 at 17:34
  • Why don't you check your assumptions when you get an error? Commented May 14, 2012 at 17:46

1 Answer 1

3

You have to tell perl what file you're trying to run with. Change to this:

function ht() { perl -i -pe 's|<!-- Mirrored from (.*?) -->\n||' "$@";}

Note the $@ instead of "$a" at the end. As @jwd points out, that's even better than $* in most cases.

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

1 Comment

Note that $@ is usually preferred to $*, since when quoted (as "$@") it will correctly deal with filenames that contain spaces.

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.