Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bashrc if: Expression Syntax error

Tags:

bash

unix

I have written 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 googled a while but no avail.

like image 932
Chani Avatar asked Jan 21 '13 13:01

Chani


1 Answers

if: Expression Syntax 

is not an error bash would give you. Perhaps your shell is not bash. In fact, as long as if stands alone, any error would not be with if itself:

$ if [somethingswrong]; then fail; fi # error, then `[` command must have space around it.
-bash: [somethingswrong]: command not found

You can check your shell by echoing $SHELL, and you can check which version of bash with $BASH_VERSION. (If the latter is unset, your shell is not bash.)

like image 192
kojiro Avatar answered Sep 20 '22 22:09

kojiro