bash aspect has been covered, your question makes me think you've come across those variables in
$_ are special variables in
perl. And they are especially found in
perl code called from the shell code.
$_ is the default variable many
perl functions and operators work on. That variable is also the default variable set by input operators.
perl -pe 'some-code' < some-input
Some-code is run for every line of some-input, with the line stored in
$_, and the content of the
$_ is printed after some-code has run.
s/regex/replacement/ operator works on
$_ by default. So you often find things like:
perl -pe 's/foo/bar/'
Which is short for:
perl -pe '$_ =~ s/foo/bar/'
$_, as far as the shell is concerned is just part of a verbatim argument passed to the
perl interpreter, it is not a shell variable. That verbatim argument is passed as
perl expression (
perl, and it's for
perl that it is interpreted as a variable).
$& is another special
perl variable that expands to whatever was matched by the last matching operator (
$ echo foo | perl -lne '
print "$_'s last character is $&" if m/.$/'
foo's last character is o
$ echo foo bar | perl -pe 's/[aeiou]+/<$&>/g'