I am learning awk. I'm confused on how to pass variables to awk in a script. Following the advice at http://www.grymoire.com/Unix/Awk.html I did (note the $ in front of $'$line'
:
#!/usr/bin/env bash
line=${1:-1}
git status -s | awk 'FNR == $'$line' {print $2}'
After some hair pulling, I got this to work by removing the first dollar sign in front of $line
:
#!/usr/bin/env bash
line=${1:-1}
git status -s | awk 'FNR == '$line' {print $2}'
So is the tutorial wrong or is there something about the behavior of variables outside of brackets that is different from those inside?