【发布时间】:2012-08-13 11:35:52
【问题描述】:
我正在尝试在 CentOS 中编写一个 bash 脚本来测试各种回声转义序列。但是,当我运行程序时
./test.sh a
我不断收到此错误消息:
错误解释:没有这样的文件或目录
这是脚本:
#! /bin/bash
# Test echo escape sequences
input=$1
case $input in
a ) echo -e "\a" testing \a;;
b ) echo -e "\b" testing \b;;
c ) echo -e "\c" testing \c;;
* ) echo Incorrect input
exit 1;;
esac
我哪里做错了?
编辑:我在 Windows XP 主机上的 VirtualBox 中运行 CentOS Minimal 来宾
编辑2:
#! bin/bash
在我的脚本中,而不是
#! /bin/bash
当我把它改成
#! /bin/bash
并运行程序./test.sh a,它只打印“a”
【问题讨论】:
-
@AdrianCornish:我怀疑它找不到
bash,要么是因为它没有安装(不太可能),要么没有安装在bin中(同样不太可能)或者它是用Windows 行保存的结局所以找不到/bin/bash^M(我之前遇到过这个问题)。 -
我的 bash 版本给出了错误 bash: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory if line ending is a problem
-
运行
file ./test.sh会得到什么? -
这是因为转义码 IHMO
-
\g 一直是铃铛字符 ;-)(天哪,我为什么记得!)
标签: bash shell scripting centos