0

I have tried fiddling with echo command to to add $_GET to a text file but looks like it does not work but escaping it with \ works may be because $ is special character in bash.

For example, echo "\$_GET" >> newfile.txt works.

Screenshot showing the weird echo behavior to me

What I wanted to ask is how does echo work in each of the following two cases in the given screenshot. The second functionality of echo is what I am not able to grasp.

2
  • In the second case, $_ "expands to the last argument to the previous command, after expansion" - see man bash under Special Parameters – steeldriver Feb 28 '18 at 5:32
  • 1
    Please don't post screenshots of text. Copy the text here and use code formatting. askubuntu.com/editing-help#code – muru Feb 28 '18 at 6:42
2

$_ is a special variable in bash and it represents the last argument of previous command executed. You executed

cat get.txt

and then

echo "$_" >> dollar.txt

It is obvious that get.txt was the last argument of previous command (cat).

Not the answer you're looking for? Browse other questions tagged or ask your own question.