13 12
发新话题
打印

为什么脚本空行会出现错误,急等回复

为什么脚本空行会出现错误,急等回复

脚本

#!/bin/sh

foo=2
echo "foo" $foo

结果
[root@server buffer]# sh shtest
: command not found
foo 2      

TOP

这种错误,跟版本有关系吗?
我的bash版本 3.1.7(1)-release

我在 3.1.17(1)-release 上运行就不会报错。      

TOP

你的空白行里是否有不可见的非法字符?      
前进、前进、再前进

TOP

看不出什么问题来 能否把你的 script 附件上来?      
'
◆ 发帖时请【突出主题】, 以便您的问题能够及时得到回复
◆ 发帖时请将您的【代码】或者【脚本】写在 [code] 和 [/code] 中间

TOP

没有非法字符,
是不是环境变量的问题呢?我从来没有设置过环境变量。
不好意思,没找到怎么粘附件
#!/bin/sh

foo = 2
echo "foo" $foo

总共就4行,空行就是 回车      

TOP

把下面命令的结果贴上来也行:
复制内容到剪贴板
代码:
$ hexdump shtest
      
'
◆ 发帖时请【突出主题】, 以便您的问题能够及时得到回复
◆ 发帖时请将您的【代码】或者【脚本】写在 [code] 和 [/code] 中间

TOP

回复 #6 TUDOU01 的帖子

我一开始 foo=2 就是没有空格的,
执行结果
[root@server buffer]# sh shtest
: command not found
foo 2      

TOP

回复 #6 dearvoid 的帖子

[root@server buffer_pool]# cat shtest
#!/bin/sh

foo=2
echo "foo" $foo
[root@server buffer_pool]# hexdump shtest
0000000 2123 622f 6e69 732f 0d68 0d0a 660a 6f6f
0000010 323d 0a0d 6365 6f68 2220 6f66 226f 2420
0000020 6f66 0d6f 000a
0000025
[root@server buffer_pool]#      

TOP

将foo = 2中=两边的空格去掉。      
前进、前进、再前进

TOP

我在哪个用户?**葱校?都是一样的,
请帮我看看,是因为环境变量有问题吗?
[root@server buffer_pool]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin


[root@server root]# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

[root@server zhchen]# cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions


[root@server zhchen]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATHHOME/bin

export PATH
unset USERNAME

[ 本帖最后由 walkright 于 2007-8-22 10:30 编辑 ]      

TOP

 13 12
发新话题