0

Normally, I can source ~/.bash_profile file as oracle using this command, but when I created a new file named test for another instance.

#!/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'

When I source this in a shell script and execute it, it throw me an errors of cd: too many arguments. I tried . (dot) instead of source. Same result.

$ 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

When I give "test" $ chmod a+x ~/test and source it, I get charset error:

$ 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”

added export CHARSET=AL32UTF8 on test file and source it, I got the same error as beginning:

$ 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

even I source the main one but it's ok when su - oracle from root.

$ 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

no error when source as root

[root@ ~]# source ~oracle/test
0

2 Answers 2

14

The issue is almost certainly your unfortunate choice of name for the alias export='cd /u02/backup/export' - which overwrites the shell builtin of the same name.

In particular, if your source the script a second time in the same shell, it will result in expressions like

export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/product/21c/dbhome_1

becoming

cd /u02/backup/export ORACLE_BASE=/opt/oracle
cd /u02/backup/export ORACLE_HOME=/opt/oracle/product/21c/dbhome_1

in which cd is passed "too many arguments".

See the somewhat related source command error from /usr/share/bash-completion/bash-completion when I open a terminal

7
  • even the "test" file has only export oracle_sid=agile and no alias at all. "export ORACLE_SID=agile" still give me error of -bash: cd: too many arguments used to source different oracle_sid profile fine in rhel6 and rhel7
    – Pepe
    Commented Oct 7, 2023 at 21:09
  • 1
    @Pepe perhaps it is aliased elsewhere? You can check with type -a export. You may want to check type -a cd as well. Commented Oct 7, 2023 at 21:21
  • $ type -a export export is aliased to `cd /u02/backup/export' export is a shell builtin $ type -a cd cd is a shell builtin cd is /usr/bin/cd cd is /bin/cd cd is /usr/bin/cd
    – Pepe
    Commented Oct 10, 2023 at 13:38
  • @Pepe right - so the first time you source your test file, export gets aliased to cd /u02/backup/export'. Any subsequent export foo command (for example, by sourcing test again) will therefore fail. Commented Oct 10, 2023 at 13:55
  • BTW test is also the name of a shell builtin and should be avoided as a command name. Commented Oct 10, 2023 at 13:56
1

Adding a bit to steeldriver's correct answer: Note that in the first 3 of the alias commands, the proposed alias is printed in black. In the 4th, however, the word export is colored. This is the first clue that export is in some way special, which it is as steeldriver has explained.

1
  • even set the new oracle_sid bold $ . oraenv ORACLE_SID = [myhr] ? agile -bash: cd: too many arguments -bash: cd: too many arguments ORACLE_HOME = [] ? waiting for me to enter oracle_home. Once the oracle_home entered I still get the cd: too many arguments **bold**ORACLE_HOME = [] ? /opt/oracle/product/21c/dbhome_1 -bash: cd: too many arguments -bash: cd: too many arguments -bash: cd: too many arguments -bash: cd: too many arguments The Oracle base remains unchanged with value /opt/oracle -bash: cd: too many arguments
    – Pepe
    Commented Oct 10, 2023 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .