$ HOMEPATH + \\不GitBash工作 [英] $HOMEPATH + \ not working in GitBash
问题描述
我试图创建一个可用于所有所有用户的脚本。
I'm trying to create a script that can be used by all by all users.
我在Windows 7机器上使用GitBash和我试图自动化行
I am using GitBash on a Windows 7 machine and the line which I am trying to automate is
alias proxyon="source $HOMEPATH/.proxy/proxy-switch.sh
现在这个问题是,
echo &HOMEPATH
\Users\<username>
GitBash,执行删除在该\\,因为它是一个特殊的性格特征,所以当我尝试运行命令proxyon,它的错误与
GitBash, when executing removes the \ as it's a special charecter, so when I try to run the command "proxyon", it error's with
sh.exe": Users<username>/.proxy/proxy-switch.sh: no such file or directory found
有没有解决这个办法吗?正如我不能改变$ HOMEPATH,因为它有一个唯一的标识符,所以它不可能是一个普遍的脚本。
Is there any way around this? As I can't change the $HOMEPATH, as it has a unique identifier, so it couldn't be a universal script.
任何帮助将appriciated。
Any help would be appriciated.
推荐答案
这里的问题是,该变量的值在 proxyon
别名是当时正在扩大正在创建,然后将文字串用反斜杠正在转义的再次的当别名运行。
The problem here is that the value of that variable is being expanded at the time the proxyon
alias is being created and then the literal string with the backslashes is being unescaped again when the alias runs.
您需要prevent的反转义之一的发生。
You need to prevent one of those unescapes from happening.
如果你想要的值 $ HOMEPATH
在执行 proxyon
来使用(而不是存在值 $ HOMEPATH
存在创建别名时),然后切换双引号对单引号别名
创建。
If you want the value of $HOMEPATH
that exists when proxyon
is executed to be used (as opposed to the value of $HOMEPATH
that exists when the alias is created) then switch the double quotes to single quotes on the alias
creation.
alias proxyon='source $HOMEPATH/.proxy/proxy-switch.sh'
您应该反正报价时使用变量扩展所以这确实应该:
You should quote the variable expansion when used anyway so this should really be:
alias proxyon='source "$HOMEPATH/.proxy/proxy-switch.sh"'
如果你想 $ HOMEPATH
时创建别名要使用(而不是 $ HOMEPATH的价值存在的价值
当别名运行存在),那么你要逃脱双引号添加到别名创建。
If you want the value of $HOMEPATH
that exists when the alias is created to be used (as opposed to the value of $HOMEPATH
that exists when the alias is run) then you want to add escaped double quotes to the alias creation.
alias proxyon="source \"$HOMEPATH/.proxy/proxy-switch.sh\""
这篇关于$ HOMEPATH + \\不GitBash工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!