I'm using WSL (Windows Subsystem for Linux) on windows 10, and installed the Amazon AWS cli on it. When I start WSL (C:\\WINDOWS\\System32\\wsl.exe in PowerShell) and then aws it works fine. If I try to run it as a one-liner (C:\\WINDOWS\\System32\\wsl.exe aws) it doesn't find the aws command. I need it as a one-liner to be able to use it from a VS Code task.

PS C:\Users\pablo.DCA> C:\\WINDOWS\\System32\\wsl.exe aws
/bin/bash: aws: command not found
PS C:\Users\pablo.DCA> C:\\WINDOWS\\System32\\wsl.exe
pablo@DCA-WS01:/mnt/c/Users/pablo.DCA$ aws
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: too few arguments

A simple echo command does work:

PS C:\Users\pablo.DCA> C:\\WINDOWS\\System32\\wsl.exe echo Hi

And so does Python (which I used to install aws):

PS C:\Users\pablo.DCA> C:\\WINDOWS\\System32\\wsl.exe python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Why does this happen? And how can I fix it, or what could I try to figure out what is going wrong?


Most likely AWS is not in a system path, like /usr/bin/. If you are adding it to your $PATH, e.g. in ~/.bashrc, it normally won't be executed unless you restart your terminal.

One option would be to use the full path to aws in your one line call from Windows:

c:\\windows\\system32\\wsl.exe /home/username/.local/bin/aws

Or you could force bash to behave as if it was invoked as a login shell with the -l (or --login) option

 c:\\windows\\system32\\wsl.exe bash -l aws

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.