Creating this question based on the advice of another users advice, it is a follow-up of this.
The scenario is that I am currently trying to create a Powershell script, that a first-time user can run, which will install a bunch of programs and complete several configuration changes. One of the configuration changes is to create a file which has two shell commands (posted below), which will then be executed everytime GitBash is loaded.
The commands I'm trying to input into the .sh file are.. (With " and ' removed)
alias proxyon=source $HOMEPATH/.proxy/proxy-switch.sh on
alias proxyoff=source $HOMEPATH/.proxy/proxy-switch.sh off
I'm trying to do this using the following command
add-content "${env:homepath}\.proxy\TempProxy.bat" "alias proxyon='source "$HOMEPATH/.proxy/proxy-switch.sh on"'"
But, the execution of the ps1 script throws an error, with the top line being
Add-Content : A positional parameter cannot be found that accepts argument '/.proxy/proxy-switch.sh'.
Now, another user told me that if i was going to use double " I would need to escape the inner quotes. The escape char in Powershell from what I can tell is ` , so I have tried the following.
add-content "${env:homepath}\.proxy\TempProxy.bat" "alias proxyon='source `"$HOMEPATH/.proxy/proxy-switch.sh on"'"
Which gave the following
The string starting: At C:\Chef\windowsdevbox-master\test.ps1:2 char:113 + add-content "${env:homepath}.proxy\TempProxy.bat" "alias proxyon='source `"$HOMEPATH/.proxy/proxy-switch.sh on" <<<< '" is missing the terminator: '.
and I also tried
add-content "${env:homepath}\.proxy\TempProxy.bat" "alias proxyon='source `"$HOMEPATH/.proxy/proxy-switch.sh on`"'"
Which doesn't error but, it doesn't add the contents of $HOMEPATH and only adds the following
alias proxyon='source "/.proxy/proxy-switch.sh on"'
Any suggestions on this would be greatly appriciated.
$HOMEPATHin the file or what the environment variable expands to? My$HOMEPATHis` which I don't think gets you the output you want. You are also using${env:homepath}` which might be what you are looking for.