![awk如何将参数$2设置为$b?](https://linux22.com/image/59980/awk%E5%A6%82%E4%BD%95%E5%B0%86%E5%8F%82%E6%95%B0%242%E8%AE%BE%E7%BD%AE%E4%B8%BA%24b%EF%BC%9F%20.png)
在 Bash 脚本中:
#!/usr/bin/bash
#grep()
#{
#grep -q
#}
if [[ -z $1 ]];
then
echo "usage: pkill -signal process name "
fi
if [[ -z $2 ]];
then
echo "error: not enough parameters "
exit
fi
kill9="9"
kill15="15"
if [ $1 -eq $kill9 ]
then
set "9"
else
set "15"
fi
ARRAY=(
`ps -ef|grep $2 |grep -v grep|awk '{print \$2}'`
)
pkill()
{
PIDTODIE=${2}
for i in ${ARRAY[@]} ;do kill $1 $i;done
}
pkill $1 $2
是否可以分配 in awk
,$2
使其变为$b
?因为$2
是 Bash 参数并且给我带来了冲突。也\$2
不起作用。
答案1
您可以awk
从 shell 中设置变量,如下所示:
$ somevar=4
$ echo | awk -v my_var="$somevar" '{print "My var is " my_var}'
My var is 4