This is not a question (although I have one at the end), but rather a solution to a problem that I would like to share if it helps someone else.
For the longest time, I got bash: [: too many argumentswhen opening a new terminal (in particular, iTerm2 on OS X with the bash -completion macport macro installed). This error occurred from a line if [ -n "$BASH_VERSION" -a -n "$PS1" -a -z "$BASH_COMPLETION_COMPAT_DIR" ]; thenin the file /opt/local/etc/bash_completion. I finally found a problem in what is export PS1='>'in mine .bash_profile. Changing PS1 to something else (for example '> ') fixes the issue with terminating bash.
Some experiments in OS X and Debian show that this problem occurs when additional expressions (with -aor -o) are added to test ( [ ]) after an expression that includes '>'. For example.
> A='>'; if [ -n "$A" ]; then echo "yes"; fi
yes
> A='>'; if [ -n "$A" -a -n "$A" ]; then echo "yes"; fi
bash: [: too many arguments
> A='> '; if [ -n "$A" -o -n "$A" ]; then echo "yes"; fi
yes
> A='>'; if [ -n "$A" -o -n "Hello" ]; then echo "yes"; fi
bash: [: too many arguments
> A='>'; if [ -n "Hello" -a -n "$A" ]; then echo "yes"; fi
yes
Is this a (known) bug in bash?
source
share