执行shell脚本中declare: not found
来源:互联网 发布:mac文件夹在哪 编辑:程序博客网 时间:2024/05/22 14:42
在做 CD 管理的程序的时候报错了
用sh 命令不可以,但是bash 确能通过。
估计期末考试会考,所以转一下,一旦用上了呢。
感谢最开始分享的那个人~
在学习 Shell 脚本的时候,有两个例子在运行时出现异常。比如,我在 test-dash.sh 脚
本输入如下内容:
echo -e "Trekshot. /a /n"
declare -i number=7
echo $number
在 Ubuntu 系统下使用 sh test-bash.sh 运行将出现如下提示信息:
-e Trekshot.
test-dash.sh: 2: declare: not found:
有两个问题:
a. echo 的参数 '-e' 怎么也打印出来了?
b. 一个简单的整数声明语句为何提示 "declare: not found"?
1.
出现此问题的原因并非代码本身有误,而是 Ubuntu 系统的问题。我们在编写脚本时,第一
行经常要写这么一行内容:#!/bin/bash. 这是对该脚本所使用的 shell 进行声明,因为
Linux 上的 shell 并非只有一种,而各个 shell 的语法是由差别的。之所以把 echo 命令
的参数误打出来,就是因为 sh 命令没有理解该语法,即当前使用的并不是 bash.下面来证
明:
获取 /bin 中相关文件的属性:
-rwxr-xr-x 1 root root 725136 2008-05-13 02:48 bash
-rwxr-xr-x 1 root root 87924 2008-06-21 00:07 dash
lrwxrwxrwx 1 root root 4 2010-03-25 14:29 sh -> dash
这表明在执行 sh test-dash.sh 的时候,我们使用的是一个叫 "dash" 的命令(注意 sh
实为链接文件),而并不是脚本第一行中声明的 bash. 这就是上面现象的原因。 其实,如
果使用 bash test-dash.sh 命令执行的话,上面两个错误根本不会出现。
2.
dash(Debian Almquist SHell) Ubuntu 自 6.10 后,将先前的 bashshell 更换成了
dash (有待考证). 在设置 dash 的说明中有下面文字:
The default /bin/sh shell on Debian and Debian-based systems is bash.
However, since the default shell is required to be POSIX-compliant, any
shell that conforms to POSIX, such as dash, can serve as /bin/sh. You may
wish to do this because dash is faster and smaller than bash.
大致意思是说默认的 shell 是 bash shell, 但只要是能兼容 POSIX 的 shell 都可以,而
dash 比 bash 速度更快、更小巧,因此 Ubuntu 安装了 dash.
3.
怎么能把 dash 去掉而使用默认的 bash?使用如下命令:
sudo dpkg-reconfigure dash
此命令是对已安装的包进行重新配置,在菜单(dash-bash-sh.png)中选择是否将 sh 链接
到 dash (Install dash as /bin/sh?) 选择否即可。
附图一:Ubuntu 下设置 dash 界面
- 执行shell脚本中declare: not found
- 执行shell脚本中declare: not found
- Shell脚本执行时出现declare: not found的解决方法
- 嵌入式 Shell脚本执行时出现declare: not found的解决方法
- Ubuntu 下运行 Shell 脚本时显示 "declare not found" 的问题
- Ubuntu 下运行 Shell 脚本时显示 "declare not found" 的问题
- Ubuntu下运行Shell脚本时显示“declare not found”的问题
- Linux shell脚本执行提示错误[[: not found
- shell脚本执行错误 $'\r':command not found
- ubuntu scripts 中declare : not found 解决
- declare:not found解决办法
- ubuntu shell 编程中的declare not found问题
- ubuntu 下运行shell时的declare not found
- eclipse中执行Ant脚本:Class not found: javac1.8
- MySql中DECLARE CONTINUE HANDLER FOR NOT FOUND 解释
- 执行shell脚本报错 '\357\273\277': command not found 解决办法
- 日常潜水-20160930-Mac执行shell脚本报错_command not found
- Mac执行shell脚本提示command not found的一种解决方案
- IO多路复用之poll总结
- java JDBC 连接数据库查询数据与直接使用sql的疑问
- 图像局部不变性特征描述
- ubuntu qq
- Java学习篇之---Maven开发跳过单元测试
- 执行shell脚本中declare: not found
- android 缓存读取与清除
- iOS 8 Tableview根据AutoLayout自动调整高度,iostableview高度
- android 获取手机内存大小
- android 把1位数,补0变成2位数
- iOS 项目中用到的一些 iOS 开源库和第三方组件
- android 自定标题栏的应用
- Android 调用系统发送短信界面,预设号码和短信内容
- 初识Maven