awk中使用shell的环境变量

awk中使用shell的环境变量
一:"'$var'"
这种写法大家无需改变用'括起awk程序的习惯,是老外常用的写法.如:
var="test"
awk 'BEGIN{print "'$var'"}'
这种写法其实际是双括号变为单括号的常量,传递给了awk.
如果var中含空格,为了shell不把空格作为分格符,便应该如下使用:
var="this is a test"
awk 'BEGIN{print "'"$var"'"}'
二:'"$var"'
这种写法与上一种类似.如果变量含空格,则变为'""$var""'较为可靠.
三.把括起awk程序的''变为"",使用"$var"
如:
$var="this is a test"
awk 'BEGIN{print "$var"}"
这是因为在""里$是特殊字符,而在''里$是普通字符.
四:export 变量,使用ENVIRON["var"]形式,
如:
$var="this is a test";export $var
awk 'BEGIN{print ENVIRON["var"]}'
五:当然也可以使用-v选项
如:
$var="this is a test"
awk -vnvar="$var" '{print nvar}'
这样便把系统变量定义成了awk变量.


( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169
Call Stack
#TimeMemoryFunctionLocation
10.0010403560{main}( ).../index.php:0
20.15221321344Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.15221321344Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.50652979736Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.50733004320Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.50943059648Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.50983076704require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.52103220792K2ControllerItem->execute( ).../k2.php:64
90.52103220792K2ControllerItem->display( ).../BaseController.php:710
100.54363489872K2ControllerItem->display( ).../item.php:78
110.54363489872K2ControllerItem->display( ).../controller.php:19
120.54753508392Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.55133528808K2ViewItem->display( ).../ViewController.php:102
140.62224093584K2ViewItem->display( ).../view.html.php:742
150.62224093584K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.62524267984include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701

( ! ) Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
Call Stack
#TimeMemoryFunctionLocation
10.0010403560{main}( ).../index.php:0
20.15221321344Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.15221321344Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.50652979736Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.50733004320Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.50943059648Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.50983076704require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.52103220792K2ControllerItem->execute( ).../k2.php:64
90.52103220792K2ControllerItem->display( ).../BaseController.php:710
100.54363489872K2ControllerItem->display( ).../item.php:78
110.54363489872K2ControllerItem->display( ).../controller.php:19
120.54753508392Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.55133528808K2ViewItem->display( ).../ViewController.php:102
140.62224093584K2ViewItem->display( ).../view.html.php:742
150.62224093584K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.62524267984include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701
back to top