浏览 2279 次
锁定老帖子 主题:shell脚本错误
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-07-08
最后修改:2010-01-23
在终端下,输入命令 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了很久没有找到原因。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-07-09
在shell脚本里单纯的执行shell命令,不赋值给变量不就用``把命令包起来,直接写命令就ok
#!/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}' |
|
返回顶楼 | |
发表时间:2009-07-09
最后修改:2009-07-09
谢谢。现在没问题了。
一句话就道出了问题的原因。 |
|
返回顶楼 | |