shell脚本错误

小弟在学习linux的shell中遇到一个问题。
在终端下,输入命令
cat /etc/passwd | awk '{FS=":"} {print "The " NR " count is " $1}'
得到结果
The 1 count is root:x:0:0:root:/root:/bin/bash
The 2 count is daemon
The 3 count is bin
The 4 count is sys
.........
但是小弟把上面代码写入到shell脚本中,文件明p.sh
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export PATH
`cat /etc/passwd | awk '{FS=":"} {print "The " NR " count is " $1}'`
然后在终端输入命令
sh p.sh
报如下错误
p.sh: 4: The: not found
输入调试命令
sh -x p.sh
报错
+ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/home/zhangyaning/bin
+ export PATH
+ cat /etc/passwd
+ awk {FS=":"} {print "The " NR " count is " $1}
+ The 1 count is root:x:0:0:root:/root:/bin/bash The 2 count is daemon The 3 count is bin The 4 count is sys The 5 count is sync The 6 count is games The 7 count is man The 8 count is lp The 9 count is mail The 10 count is news The 11 count is uucp The 12 count is proxy The 13 count is www-data The 14 count is backup The 15 count is list The 16 count is irc The 17 count is gnats The 18 count is nobody The 19 count is libuuid The 20 count is syslog The 21 count is klog The 22 count is hplip The 23 count is avahi-autoipd The 24 count is gdm The 25 count is saned The 26 count is pulse The 27 count is messagebus The 28 count is polkituser The 29 count is avahi The 30 count is haldaemon The 31 count is zhangyaning The 32 count is alex The 33 count is arod
p.sh: 1: The: not found
在终端输入 echo $PATH
结果:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
小弟刚学习shell不久,google了很久没有找到原因。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值