Bashrc if: Expression Syntax error
I wrote the following .bashrc:
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
function up( )
{
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
P=$P/..
done
cd $P
export MPWD=$P
}
function back( )
{
LIMIT=$1
P=$MPWD
for ((i=1; i <= LIMIT; i++))
do
P=${P%/..}
done
cd $P
export MPWD=$P
}
However, after saving when I did source .bashrc
, I got the following error:if: Expression Syntax.
What am I doing wrong? I've googled but to no avail.
+3
source to share
1 answer
if: Expression Syntax
is not a bash bug. Your shell may not be bash. In fact, as long as if
it stands alone, no error will occur with if
:
$ if [somethingswrong]; then fail; fi # error, then `[` command must have space around it.
-bash: [somethingswrong]: command not found
You can check your shell by repeating $SHELL
and you can check which version of bash with $BASH_VERSION
. (If the latter is not installed, your shell is not bash.)
+7
source to share