gpt4 book ai didi

bashrc 如果 : Expression Syntax error

转载 作者:行者123 更新时间:2023-11-29 09:03:18 25 4
gpt4 key购买 nike

我写了以下 .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.

我做错了什么?我用谷歌搜索了一段时间但无济于事。

最佳答案

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_VERSION 检查哪个版本的 bash。 (如果后者未设置,则您的 shell 不是 bash。)

关于bashrc 如果 : Expression Syntax error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14440105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com