小编Ani*_*nil的帖子

环境变量未在命令行参数内展开

我有一个文件user-pid.out2,其中包含“usernumber”和“process id”作为两列。根据用户编号我想找到相应的进程ID。下面的前两行没有正确显示输出,但是当我在第 3 行和第 4 行中将用户硬编码为 62 时,它显示了与用户 62 对应的进程 ID。有人可以帮忙吗?

USR=62
usrpid=`awk '$1 == "$USR" {print $2}' /home/hu/batchhu/dbscripts_tst2/user-pid.out2`
echo "first:" $USR $usrpid
# This shows 62 and blank for process id

usrpid=`awk '$1 == "62" {print $2}' /home/hu/batchhu/dbscripts_tst2/user-pid.out2`
echo  "second:" $USR $usrpid
# This shows 62 and process id corresponding to this user in the file user-pid.out2
Run Code Online (Sandbox Code Playgroud)

shell bash awk quoting variable-substitution

2
推荐指数
1
解决办法
3062
查看次数

标签 统计

awk ×1

bash ×1

quoting ×1

shell ×1

variable-substitution ×1