大家好,这里是 Lucifer三思而后行,专注于提升数据库运维效率。
目录
问题描述
今天有群友在 SUSE11 版本运行 Oracle 一键安装脚本时报错如下:
./OracleShellInstall: line 152: declare: -l: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
./OracleShellInstall: line 153: declare: -u: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
./OracleShellInstall: line 154: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
看提示信息是 declare 命令没有 -u、-l 和 -A 选项。

因为脚本里定义变量是使用以下方式:
# 数据库是否开启归档模式
declare -l enable_arch=true
# 仅配置操作系统,默认值为 N,包括配置操作系统以及解压软件安装包
declare -u only_conf_os=N
# 定义一个用于保存 root 用户需要设置 SSH 信任的 IP 地址
declare -a ssh_ips
# 定义用于保存心跳 IP 的关联数组
declare -A rac_priv_ips
脚本并未适配 bash-4 以下版本,所以未曾考虑命令不支持的问题。
原因分析
在我的 rhel8 主机上查看这 3 个参数的含义:
Options which set attributes:
-A to make NAMEs associative arrays (if supported)
-l to convert NAMEs to lower case on assignment
-u to convert NAMEs to upper case on assignment
查看 Bash Changelog 中 bash 4.0 的相关变更情况 Imported from …/bash-4.0-rc1.tar.gz.:
## shell 提供关联数组变量,也就是对 -A 参数的支持
+ii. The shell provides associative array variables, with the appropriate
+ support to create, delete, assign values to, and expand them.
+
# 对 declare 命令新增了 -l 和 -u 命令
+jj. The `declare' builtin now has new -l (convert value to lowercase upon
+ assignment) and -u (convert value to uppercase upon assignment) options.
+ There is an optionally-configurable -c option to capitalize a value at
+ assignment.
再看一下每个版本中对于 declare 命令的扩展更新:
## bash-4.0-rc1
+n. The -p option to `declare' now displays all variable values and attributes
+ (or function values and attributes if used with -f).
+jj. The `declare' builtin now has new -l (convert value to lowercase upon
+ assignment) and -u (convert value to uppercase upon assignment) options.
+ There is an optionally-configurable -c option to capitalize a value at
+ assignment.
## bash-4.2
+e. declare/typeset has a new `-g' option, which creates variables in the
+ global scope even when run in a shell function.
## bash-4.4
+f. The `-p' option to declare and similar builtins will display attributes for
+ named variables even when those variables have not been assigned values
+ (which are technically unset).
+p. Bash no longer attempts to perform compound assignment if a variable on the
+ rhs of an assignment statement argument to `declare' has the form of a
+ compound assignment (e.g., w='(word)' ; declare foo=$w); compound
+ assignments are accepted if the variable was already declared as an array,
+ but with a warning.
+
+q. The declare builtin no longer displays array variables using the compound
+ assignment syntax with quotes; that will generate warnings when re-used as
+ input, and isn't necessary.
## bash-5.0
+aa. The `@A' variable transformation now prints a declare command that sets a
+ variable's attributes if the variable has attributes but is unset.
+
+bb. `declare' and `local' now have a -I option that inherits attributes and
+ value from a variable with the same name at a previous scope.
## bash-5.2
+bb. Array references using `@' and `*' that are the value of nameref variables
+ (declare -n ref='v[@]' ; echo $ref) no longer cause the shell to exit if
+ set -u is enabled and the array (v) is unset.
+gg. Since there is no `declare -' equivalent of `local -', make sure to use
+ `local -' in the output of `local -p'.
可以看到从 bash-4.0 版本开始,declare 命令才支持 -u、-l 和 -A 选项。而 SUSE11 的 bash 版本为 3.2.57:

显然是不支持这三个选项,所以报错是情理之中了。
解决方案
解决方法也就很有限了,可以手动执行安装,如果想用脚本则建议使用 SUSE12 安装。当然,为了后面大家遇到问题可以第一时间知道原因,我加了一个判断进行限制提示:
# 增加 bash 版本限制
bash_version=$(echo "$BASH_VERSION" | cut -d '.' -f1)
if [[ $bash_version ]] && ((bash_version < 4)); then
printf "\n\E[1;31m%-20s\n\E[0m\n" "本脚本不支持 Bash 版本低于 4 执行安装,当前 Bash 版本为:$bash_version,已退出!"
exit 1
fi
如果 bash 版本低于 4,执行报错:
SUSE11 # ./OracleShellInstall
本脚本不支持 Bash 版本低于 4 执行安装,当前 Bash 版本为:3,已退出!
问题到此结束,记录以作参考。愿此微薄之力,可助君一二。
往期精彩文章推荐
Oracle 数据库启动过程之 nomount 详解
Oracle RAC 修改系统时区避坑指南(深挖篇)
Ubuntu 22.04 一键安装 Oracle 11G RAC
使用 dbops 快速部署 MySQL 数据库
Oracle RAC 启动顺序,你真的了解吗?
达梦数据库一键安装脚本(免费)一篇文章让你彻底掌握 Python 🔥
一篇文章让你彻底掌握 Python
一篇文章让你彻底掌握 Shell 🔥
Oracle 监控 EMCC 13.5 安装部署超详细教程 🔥
Oracle 一键巡检自动生成 Word 报告 🔥
Oracle一键安装脚本的 21 个疑问与解答 🔥
Oracle一键巡检脚本的 21 个疑问与解答 🔥
全网首发:Oracle 23ai 一键安装脚本 🔥
Oracle 19C 最新 RU 补丁 19.24 ,一键安装! 🔥
Oracle Linux 6 一键安装 Oracle 11GR2 RAC
Oracle Linux 7.9 一键安装 Oracle 19C
Oracle Linux 8.9 一键安装 Oracle 19C RAC
Oracle Linux 9.4(aarch64) 一键安装 Oracle 19C 🔥
openEuler 20.03 LTS SP4 一键安装 Oracle 19C 🔥
openEuler 22.03 LTS SP4 一键安装 Oracle 19C RAC
RHEL 7.9 一键安装 Oracle 19C 19.23 RAC
Redhat 8.4 一键安装 Oracle 11GR2
RedHat 9.4(aarch64) 一键安装 Oracle 19C
龙蜥 Anolis 7.9 一键安装 Oracle 19C 19.23
龙蜥 Anolis OS 8.8 一键安装 Oracle 19C
SUSE 15 SP5 一键安装 Oracle 19C
统信 UOS V20 1070(a) 一键安装 Oracle 11GR2
Ubuntu 22.04 一键安装 Oracle 19C
Ubuntu 14.04 一键安装 Oracle 19C
银河麒麟 Kylin V10 SP3 一键安装 Oracle 19C 🔥
银河麒麟 Kylin V10 SP3 一键安装 Oracle 11GR2 RAC
Oracle DataGuard GAP 修复手册 🔥
优化 Oracle:最佳实践与开发规范
DBA 必备:Linux 软件源配置全攻略 🔥
Linux 一键配置时钟同步全攻略 🔥
Starwind 配置 ISCSI 共享存储
SUSE 15 SP3 安装 Oracle 19C RAC 数据库
达梦 8 数据库安装手册 🔥
Oracle 12CR2 RAC 安装避坑宝典
Linux7 安装 Oracle 19C RAC 详细图文教程 🔥
Oracle ADG 搭建 RAC to Single 详细教程
Oracle DataGuard GAP 修复手册 🔥
Oracle 分区表之在线重定义
AutoUpgrade 快速升级 Oracle 数据库
Oracle 数据库巡检命令手册 🔥
Oracle 数据坏块的 N 种修复方式 🔥
数据库 SQL 开发入门教程
超全 Linux 基础命令总结 🔥
VMware 虚拟机安装 Linux 系统
Linux 安装 MySQL 详细教程
教你玩转 SQLPLUS,工作效率提升 200%
感谢您的阅读,这里是 Lucifer三思而后行,欢迎 点赞+关注,我会持续分享数据库知识、运维技巧。




