使用"'$var'"(或者'"$var"')形式
shell
root@ypyu-VirtualBox:/usr/local/shellscript/code/CH12# awk 'BEGIN{print "'$var'"}'ide
testthis
root@ypyu-VirtualBox:/usr/local/shellscript/code/CH12# awk 'BEGIN{print "$var"}'spa
$varcode
若是var中含空格,爲了shell不把空格做爲分格符,便應該以下使用:orm
var="this is a test"
awk 'BEGIN{print "'"$var"'"}'ip