通常,我可以使用此命令将 ~/.bash_profile 文件作为 oracle 来获取,但是当我为另一个实例创建了一个名为 test 的新文件时。
#!/bin/bash
# User specific environment and startup programs
# Oracle Settings
# User specific environment and startup programs
if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
#export PATH
# Oracle Settings
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/21c/dbhome_1
export ORACLE_SID=agile
export ORA_INVENTORY=/opt/app/oraInventory
export PATH=$PATH:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch
export DISPLAY="localhost:10.0"
export LC_ALL=C
alias sp='sqlplus / as sysdba'
alias script='cd /u02/scripts/agile'
alias software='cd /u02/software'
alias export='cd /u02/backup/export'
当我在 shell 脚本中引用此代码并执行它时,它会抛出错误 cd: too many parameters。我尝试使用 . (dot) 代替 source。结果相同。
$ source test
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
当我给出“测试”$ chmod a+x ~/test
并将其作为源时,出现字符集错误:
$ ls -ltr test
-rwxr-xr-x. 1 oracle oinstall 724 Oct 6 14:37 test
$ souce test
GLib: Cannot convert message: Could not open converter from “UTF-8” to “AL32UTF8”
在测试文件上添加了 export CHARSET=AL32UTF8 并将其作为源,我得到了与开始时相同的错误:
$ vi test
$ source test
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
甚至我找到了主要的源代码,但从 root 执行 su - oracle 时也没问题。
$ source .bash_profile
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
-bash: cd: too many arguments
以 root 身份启动时无错误
[root@ ~]# source ~oracle/test
答案1
问题几乎肯定是您对别名的选择不当export='cd /u02/backup/export'
- 它会覆盖同名的 shell 内置命令。
特别是,如果你在同一个 shell 中第二次执行该脚本,它将导致如下表达式
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/21c/dbhome_1
变得
cd /u02/backup/export ORACLE_BASE=/opt/oracle
cd /u02/backup/export ORACLE_HOME=/opt/oracle/product/21c/dbhome_1
其中cd
传递了“太多参数”。
参见相关内容当我打开终端时,/usr/share/bash-completion/bash-completion 出现源命令错误
答案2
对steeldriver的正确答案做一点补充:请注意,在前三个别名命令中,建议的别名是用黑色打印的。然而,在第四个命令中,export这个词是彩色的。这是第一个线索,表明export在某种程度上是特殊的,正如steeldriver所解释的那样。