Bash Internal variables $_

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Outputs the last field from the last command executed, useful to get something to pass onwards to another command:

 ~> $ ls *.sh;echo $_
testscript1.sh  testscript2.sh
testscript2.sh

It gives the script path if used before any other commands:

test.sh:

#!/bin/bash
echo "$_"

Output:

~> $ ./test.sh # running test.sh
./test.sh

Note: This is not a foolproof way to get the script path



Got any Bash Question?