如果在.bashrc:防爆pression语法错误 [英] bashrc if: Expression Syntax error

查看:181
本文介绍了如果在.bashrc:防爆pression语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了下面的.bashrc:

 #的.bashrc
#源的全局定义
如果[-f的/ etc / bashrc中];然后
        。在/ etc / bashrc中
科幻#用户特定的别名和函数
功能了()
{
LIMIT = $ 1
P = $ PWD
为((i = 1; I< =限制;我+ +))

    P = $ P / ..
DONE
CD $ P
出口MPWD = $ P
}机能恢复()
{
LIMIT = $ 1
P = $ MPWD
为((i = 1; I< =限制;我+ +))

    P = $ {P%/ ..}
DONE
CD $ P
出口MPWD = $ P
}

但是,节省,当我做了源的.bashrc 之后,我得到了以下错误:如果:如:pression语法

我是什么做错了吗?我GOOGLE了一段时间,但无济于事。


解决方案

 ,如果:防爆pression语法

是不是一个错误的bash会给你。也许你的shell是不是bash。其实,只要如果是独立的,任何错误不会与如果本身:

  $如果[somethingswrong]然后失败;科幻#错误,​​`[`命令必须有它周围的空间。
-bash:[somethingswrong]:命令未找到

您可以通过回 $ SHELL 检查你的shell,你可以检查的bash的版本与 $ BASH_VERSION 。 (如果是后者未设置,你的shell不是bash的。)

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.

解决方案

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.)

这篇关于如果在.bashrc:防爆pression语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆