2013-01-21 9 views
3

我寫了下面的.bashrc:的.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 
} 

然而,保存,當我做source .bashrc後,我得到了以下錯誤:if: Expression Syntax.

我在做什麼錯?我GOOGLE了一段時間,但無濟於事。

+2

檢查你的shell是否使用echo $ SHELL – JohnTortugo

+0

@JohnTortugo謝謝,我使用c shell並在bashrc中進行了更改。 – Chani

回答

7
if: Expression Syntax 

是不是一個錯誤bash會給你。也許你的shell不是bash。其實,只要if是獨立的,任何錯誤不會與if本身:

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

您可以通過回$SHELL檢查你的shell,您可以檢查的bash的版本有$BASH_VERSION。 (如果後者未設置,你的shell不是bash。)

+1

謝謝,我正在使用c shell並在bashrc中進行更改。 – Chani

相關問題