How to tell bash not to expand $ _ variable?

I want to use some perl line, for example:

perl -pe "$_=~s///e"

The problem is that bash continues to expand the variable "$ _". I could express the perl expression in single quotes, but that would prevent me from adding some variables to the script.

Is there a way to stop bash from expanding the $ _ variable?

+5
source share
3 answers
perl -pe '$_=~s///e'

or

perl -pe "\$_=~s///e"
+11
source

First: you know what you can use $ENV{myvariable}to access environment variables, right? And what you do not need to indicate $_when using m//, s///and tr///?

, perl, , , perl-.

perl -we 'my ($var1, $var2, $var3) = @ARGV;' "$MYFOO" "$BAR" "$baz"

, .

, -p -n, .

perl -pwe 'BEGIN { my $var1 = shift; my $var2 = shift } #code goes here'
    "$MYFOO" "$BAR" file1 file2 

shift BEGIN @ARGV, while -p -n.

+5

Mix-and-match.

perl -pe '$_=~s///e; echo "'"$idontknowperl"'"'

As long as the sections quoted are adjacent to each other, it will be considered the only argument.

+1
source

All Articles