Windows – How to use %LocalAppData% with git bash in Windows


I want to automate my process of align and signing an APK (an app for Android). I use git bash as terminal inside VSCODE.

For this I am concatenating the commands I need into a shell script but I got a problem with the windows variables. Since the android SDK installs it self automatically on C:\Users\myUserName\AppData\Local I can access it using %LocalAppData% on CMD but not in bash because it throws:

$ %LocalAppData%
bash: fg: %LocalAppData%: no such job

Of course I would just write the complete path but it will make my script useless on my laptop and/or another machine that is not where I wrote the script.

Is there a way to access %LocalAppData% with git bash?

Best Answer

Is there a way to access %LocalAppData% with git bash?

Assuming git bash maps Windows environment variables to bash variables then you access them using $VARIABLENAME.

Cygwin bash example:


To list environment variables use env:

$ env
COMMONPROGRAMFILES=C:\Program Files\Common Files
PSModulePath=C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
CommonProgramW6432=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files

Further Reading

  • An A-Z Index of the Bash command line for Linux - An excellent reference for all things Bash command line related.
  • env - Display, set, or remove environment variables, Run a command in a modified environment.
  • shell variables - You can use variables in bash as in any programming language. There are no data types so a variable can contain a number, or a string of characters.