I'm trying to create a script that can be used by all by all users.
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
Now the issue with this is,
echo &HOMEPATH
\Users\<username>
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
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.
Any help would be appriciated.
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.You need to prevent one of those unescapes from happening.
If you want the value of
$HOMEPATH
that exists whenproxyon
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 thealias
creation.You should quote the variable expansion when used anyway so this should really be:
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.