3

I am trying to sign onto the bash Windows Subsystem for Linux when I get this error:

-bash: /home/User1/.profile: line 28: syntax error near unexpected token `('

Before getting this error I was trying to permanently put a directory in my path using the export PATH:$PATH function.

my /.profile file

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi
export PATH=/home/user1/.local/bin:/home/janeen/bin:/home/janeen/miniconda3/bin:/home/User1/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/Docker/Docker/resources/bin:/c/Program Files (x86)/Common Files/Oracle/Java/javapath_target_34052312:/c/Windows/System32:/c/Windows:/c/Windows/System32/wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Strawberry/c/bin:/c/Strawberry/perl/site/bin:/c/Strawberry/perl/bin:/c/Users/User1/AppData/Local/Programs/Python/Python36:/c/Users/Janeen/AppData/Local/Programs/Python/Python36/Scripts:/c/Users/User1/AppData/Local/Programs/Python/Python37-32/Scripts:/c/Users/Janeen/AppData/Local/Programs/Python/Python37-32:/c/Users/User1/AppData/Local/Microsoft/WindowsApps:/e/Program Files (x86)/TBtools/bin:/snap/bin:/software/samtools
pa4080
  • 29,831
  • 1
    is there a reason you do not include the contents of /home/User1/.profile? and more specifically the lines around line 28? It is going to be pretty impossible to answer this without ... – Rinzwind Oct 24 '19 at 06:20
  • Your export command is incorrect. You need to use export PATH=/some/new/path:$PATH where you assign new value to the PATH variable and export it simultaneously. But the cited syntax error, probably, is related to some other typo. – pa4080 Oct 24 '19 at 07:11
  • now the error is resolve but I am having this error now -bash: /home/janeen/.profile: Permission denied when typing bash at the comment line – Jane1989 Oct 24 '19 at 07:54

2 Answers2

1

First, you need to quote the directory paths that include white spaces and special characters, or escape each of these characters by back slash - reference.

Second, the canonical way to change the PATH is:

export PATH=/some/new/path:$PATH

Thus you are adding some new path in front to the existing value of PATH, otherwise you wont be able to execute fluently couple of commands that are located in the default path.

Third within WSL, by default, the Windows drives C:, D: and so on, are mounted under /mnt - i.e. /mnt/c, /mnt/d, etc. Here is example:

export PATH='/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath_':$PATH

Forth, there shouldn't be available file /.profile, it must be located in the users home directory ~/.profile ($HOME/.profile). Also your .profile file looks incomplete here is how the default one looks like: WSL .profile. In the profile file that is posted within the question the .bashrc file is not sourced.

pa4080
  • 29,831
  • Hello thanks but this my path within my /.profile. When I type echo $PATH the software/samtools is not there. Also its now showing a permission denied for /.profile and the user, directory name and host name of my bash subsystem has not color, but if I type bash again the blue and green colors return. – Jane1989 Oct 24 '19 at 08:25
  • Hi, @Jane1989, I've updated the answer. – pa4080 Oct 24 '19 at 08:52
  • is it incomplete because of the last line does not have a fi – Jane1989 Oct 24 '19 at 08:54
  • Thank you much for your help but what do you mean by the .bashrc file is not source. I am very new to linux so I am not familiar with these statements. also I did you way for the export file and still not after login again not showing in the path. – Jane1989 Oct 24 '19 at 08:56
  • @Jane1989: This is how the .profile file looks like on my WSL: https://paste.ubuntu.com/p/Np6p6YNd2p/ ... There is a line . "$HOME/.bashrc", here is reference: https://bash.cyberciti.biz/guide/Source_command – pa4080 Oct 24 '19 at 08:59
  • if running bash

    if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi

    set PATH so it includes user's private bin if it exists

    if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi

    set PATH so it includes user's private bin if it exists

    if [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH" fi

    – Jane1989 Oct 24 '19 at 09:03
  • this the /.profile on my computer – Jane1989 Oct 24 '19 at 09:06
0

When the Linux instance is setup the host machine PATH variable is cloned into the Linux machine .bashrc file (with conversions made to the paths to make them work from inside WSL).

source: https://lifesaver.codes/answer/problems-with-windows-path-variable-getting-imported-1890

When the PATH variable contains spaces you get this error, most likely wrapping the entire value of PATH in quotes will fix it. you can also remove the offending pathes if you don't need them.

If you need a more permanent solution, meaning a "fix once per host machine" instead of "once per guest machine creation" try going down this path:

https://github.com/microsoft/WSL/issues/1640#issuecomment-276408942