gpt4 book ai didi

cygwin - 光盘: too many arguments - spaces properly escaped + quoted?

转载 作者:行者123 更新时间:2023-12-02 04:22:10 26 4
gpt4 key购买 nike

使用 cygwin 终端,我的 .bashrc 中有以下内容:

export WINHOME="/cygdrive/c/Users/userName"
export TUTORING="$WINHOME/Desktop/Coding\ Projects/Tutoring/"

当我打开 cygwin 时,会发生以下情况:

$ cd $TUTORING
-bash: cd: too many arguments

然后我尝试了:

$ echo $TUTORING
/cygdrive/c/Users/userName/Desktop/Coding\ Projects/Tutoring

复制粘贴 echo 的输出:

cd /cygdrive/c/Users/userName/Desktop/Coding\ Projects/Tutoring 

这似乎有效。知道为什么 cd 我的变量有问题吗?

最佳答案

分词发生在变量扩展之后。来自 man bash:

The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.

The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words using these characters as field terminators.

正确的方法是使用双引号:

export TUTORING="$WINHOME/Desktop/Coding Projects/Tutoring/"
cd "$TUTORING"

关于cygwin - 光盘: too many arguments - spaces properly escaped + quoted?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54893108/

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