Your script (with single quotes around an awk script) will work as expected:
$ cat script-single #!/bin/bash line="foo bar" echo $line | awk '{print $1}' $ ./script-single test foo
Next, the following will be broken (the script displays an empty string):
$ cat script-double #!/bin/bash line="foo bar" echo $line | awk "{print $1}" $ ./script-double testβ
Note the double quotes around the awk program.
Because double quotes extend the $1 variable, the awk command will get a script {print test} that prints the contents of the awk test variable (which is empty). Here is a script that shows that:
$ cat script-var #!/bin/bash line="foo bar" echo $line | awk -v test=baz "{print $1}" $ ./script-var test baz
Related Reading: Bash Reference Guide - Citation and Shell Extensions
source share