Shell脚本执行时出现declare: not found的解决方法

简介:
错误现象:
deployer@andy-VirtualBox:~/pds/EB$ sh build.sh
build.sh: 18: build.sh: declare: not found

build.sh: 25: build.sh: declare: not found

build.sh: 32: build.sh: declare: not found

原因分析:
root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/sh
/bin/sh: symbolic link to `dash'
root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/dash
/bin/dash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x5d23ca7cbab4993f295d1089b4860eb32d406fab, stripped
root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/bash
/bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xf199a4a89ac968c2e0e99f2410600b9d7e995187, stripped
root@andy-VirtualBox:/home/deployer/pds/EB# ln -s /bin/bash /bin/sh
ln: failed to create symbolic link `/bin/sh': File exists
root@andy-VirtualBox:/home/deployer/pds/EB# ln -s /bin/bash /bin/sh -f
root@andy-VirtualBox:/home/deployer/pds/EB# file /bin/sh
/bin/sh: symbolic link to `/bin/bash'
重点看红色字体部分,可以看到,初始是/bin/sh是到/bin/dash的链接。修改后为到/bih/bash的链接。
所以,问题出在,我们的脚本是bash的脚本。而用dash去执行。虽然dash和bash都是shell,在执行时还是有差别的。
解决方法:
(1)执行时由sh build.sh变成bash build.sh可以解决此问题。
(2)ln -s /bin/bash /bin/sh -f
(3)sudo dpkg-reconfigure dash 进行配置,道理同(2)
归结来说,为两种方式。以上两种方法都可以实现。

感谢http://blog.sina.com.cn/s/blog_7cb1c50e0100rapz.html博主。


本文转自博客园zhyiwww 的博客,原文链接:http://www.blogjava.net/zhyiwww/,如需转载请自行联系原博主。

目录
相关文章
|
21天前
|
弹性计算 Shell Perl
ecs服务器shell常用脚本练习(二)
【4月更文挑战第1天】shell代码训练(二)
104 1
|
24天前
|
Java Shell
SpringBoot启动脚本Shell
SpringBoot启动脚本Shell
16 0
|
1天前
|
Java 关系型数据库 MySQL
Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
【4月更文挑战第12天】Elasticsearch【问题记录 01】启动服务&停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含shell脚本文件)
17 3
|
4天前
|
运维 监控 Shell
利用Shell脚本编写局域网监控软件:实时监测主机连接情况
本文介绍了如何使用Shell脚本创建一个局域网监控工具,以实时检查主机连接状态。脚本包括扫描IP地址范围检测主机可达性及使用`netstat`监控ESTABLISHED连接。此外,还展示了如何每60秒将连接数数据自动提交到指定网站API,以便实时跟踪网络活动。这个自动化监控系统有助于提升网络安全性和故障排查效率。
22 0
|
5天前
|
Shell
Shell脚本之流程控制语句
Shell脚本之流程控制语句
|
6天前
|
JSON 运维 监控
训练shell常用脚本练习(三)
【4月更文挑战第14天】shell代码训练(三)
21 1
|
10天前
|
存储 弹性计算 Shell
ecs服务器shell常用脚本练习(十)
【4月更文挑战第11天】shell代码训练(十)
140 0
|
10天前
|
弹性计算 Shell Go
ecs服务器shell常用脚本练习(九)
【4月更文挑战第10天】shell代码训练(八)
131 0
|
14天前
|
弹性计算 Shell Linux
ecs服务器shell常用脚本练习(六)
【4月更文挑战第4天】shell代码训练(六)
108 0
|
19天前
|
弹性计算 Shell 应用服务中间件
ecs服务器shell常用脚本练习(四)
【4月更文挑战第4天】shell代码训练(四)
96 0