0

Recently I installed Bash on Ubuntu on Windows using WSL to use OpenFOAM. But when I installed OpenFOAM it is giving me the error like:

-bash: eval: line 38: syntax error near unexpected token `('
-bash: eval: line 38: 
`PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:
/usr/games:/usr/local/games:/mnt/c/Program:Files: 
(x86)/Common:Files/Oracle/Java/javapath_target_495862015:
/mnt/c/oraclexe/app/oracle/product/10.2.0/server/BIN:
/mnt/c/ProgramData/Oracle/Java/javapath_target_496471312:
/mnt/d/PYTHON:INSTALLED:INSTALLED/Scripts:/mnt/c/MinGW/bin:
Files/PTC/MKSTOO~1/bin64:Files/PTC/MKSTOO~1/bin:
Files/PTC/MKSTOO~1/bin/X11:Files/PTC/MKSTOO~1/mksnt: 
(x86)/PC:Connectivity:Solution:Files/Common:
Files/microsoft:shared/Windows:Live:
/mnt/c/Windows/System32:/mnt/c/Windows:
/mnt/c/Windows/System32/wbem:
/mnt/c/Windows/System32/WindowsPowerShell/v1.0:
(x86)/Windows:Live/Shared: 
(x86)/Calibre2:Files/Microsoft/Web:Platform:Installer: 
`(x86)/Microsoft:ASP.NET/ASP.NET:Web:Pages/v1.0:Files/Microsoft:SQL:Server/110/Tools/Binn:/mnt/d/MATLAB:installed/R2014b/runtime/win64:installed/R2014b/bin:(x86)/NVIDIA:Corporation/PhysX/Common:Server/120/Tools/Binn:

`(x86)/Skype/Phone:Files/LENOVO/easyplussdk/bin:Files/Calibre2:Server/100/Tools/Binn:Server/100/DTS/Binn:Server/100/Tools/Binn/VSShell/Common7/IDE:Server/Client:SDK/ODBC/130/Tools/Binn:Server/130/Tools/Binn:Server/130/DTS/Binn:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Windows/System32/OpenSSH:Files/Java/jdk1.7.0/bin:(x86)/Nmap:/mnt/c/MinGW/msys/1.0/bin:/mnt/c/Users/asus/AppData/Local/Microsoft/WindowsApps:/snap/bin'
    -bash: eval: line 62: syntax error near unexpected token `('
    -bash: eval: line 62: `PATH=/opt/OpenFOAM/ThirdParty-v1806/platforms/linux64Gcc63/openmpi-1.10.4/bin:/opt/OpenFOAM/ThirdParty-v1806/platforms/linux64/gcc-6.3.0/bin:/home/maddy/OpenFOAM/maddy-v1806/platforms/linux64Gcc63DPInt32Opt/bin:/opt/OpenFOAM/site/v1806/platforms/linux64Gcc63DPInt32Opt/bin:/opt/OpenFOAM/OpenFOAM-v1806/platforms/linux64Gcc63DPInt32Opt/bin:/opt/OpenFOAM/OpenFOAM-v1806/bin:/opt/OpenFOAM/OpenFOAM-v1806/wmake:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program:Files:(x86)/Common:Files/Oracle/Java/javapath_target_495862015:/mnt/c/oraclexe/app/oracle/product/10.2.0/server/BIN:/mnt/c/ProgramData/Oracle/Java/javapath_target_496471312:/mnt/d/PYTHON:INSTALLED:INSTALLED/Scripts:/mnt/c/MinGW/bin:Files/PTC/MKSTOO~1/bin64:Files/PTC/MKSTOO~1/bin:Files/PTC/MKSTOO~1/bin/X11:Files/PTC/MKSTOO~1/mksnt:(x86)/PC:Connectivity:Solution:Files/Common:Files/microsoft:shared/Windows:Live:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:(x86)/Windows:Live/Shared:(x86)/Calibre2:Files/Microsoft/Web:Platform:Installer:(x86)/Microsoft:ASP.NET/ASP.NET:Web:Pages/v1.0:Files/Microsoft:SQL:Server/110/Tools/Binn:/mnt/d/MATLAB:installed/R2014b/runtime/win64:installed/R2014b/bin:(x86)/NVIDIA:Corporation/PhysX/Common:Server/120/Tools/Binn:(x86)/Skype/Phone:Files/LENOVO/easyplussdk/bin:Files/Calibre2:Server/100/Tools/Binn:Server/100/DTS/Binn:Server/100/Tools/Binn/VSShell/Common7/IDE:Server/Client:SDK/ODBC/130/Tools/Binn:Server/130/Tools/Binn:Server/130/DTS/Binn:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Windows/System32/OpenSSH:Files/Java/jdk1.7.0/bin:

    (x86)/Nmap:/mnt/c/MinGW/msys/1.0/bin:/mnt/c/Users/asus/AppData/Local/Microsoft/WindowsApps:/snap/bin:'
        -bash: eval: line 38: syntax error near unexpected token `('
        -bash: eval: line 38: `PATH=/opt/OpenFOAM/ThirdParty-v1806/platforms/linux64Gcc63/gperftools-2.5/bin:/opt/OpenFOAM/ThirdParty-v1806/platforms/linux64Gcc63/openmpi-1.10.4/bin:/opt/OpenFOAM/ThirdParty-v1806/platforms/linux64/gcc-6.3.0/bin:/home/maddy/OpenFOAM/maddy-v1806/platforms/linux64Gcc63DPInt32Opt/bin:/opt/OpenFOAM/site/v1806/platforms/linux64Gcc63DPInt32Opt/bin:/opt/OpenFOAM/OpenFOAM-v1806/platforms/linux64Gcc63DPInt32Opt/bin:/opt/OpenFOAM/OpenFOAM-v1806/bin:/opt/OpenFOAM/OpenFOAM-v1806/wmake:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program:Files:(x86)/Common:Files/Oracle/Java/javapath_target_495862015:/mnt/c/oraclexe/app/oracle/product/10.2.0/server/BIN:/mnt/c/ProgramData/Oracle/Java/javapath_target_496471312:/mnt/d/PYTHON:INSTALLED:INSTALLED/Scripts:/mnt/c/MinGW/bin:Files/PTC/MKSTOO~1/bin64:Files/PTC/MKSTOO~1/bin:Files/PTC/MKSTOO~1/bin/X11:Files/PTC/MKSTOO~1/mksnt:(x86)/PC:Connectivity:Solution:Files/Common:Files/microsoft:shared/Windows:Live:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:(x86)/Windows:Live/Shared:(x86)/Calibre2:Files/Microsoft/Web:Platform:Installer:(x86)/Microsoft:ASP.NET/ASP.NET:Web:Pages/v1.0:Files/Microsoft:SQL:Server/110/Tools/Binn:/mnt/d/MATLAB:installed/R2014b/runtime/win64:installed/R2014b/bin:(x86)/NVIDIA:Corporation/PhysX/Common:Server/120/Tools/Binn:(x86)/Skype/Phone:Files/LENOVO/easyplussdk/bin:Files/Calibre2:Server/100/Tools/Binn:Server/100/DTS/Binn:Server/100/Tools/Binn/VSShell/Common7/IDE:Server/Client:SDK/ODBC/130/Tools/Binn:Server/130/Tools/Binn:Server/130/DTS/Binn:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Windows/System32/OpenSSH:Files/Java/jdk1.7.0/bin:(x86)/Nmap:/mnt/c/MinGW/msys/1.0/bin:/mnt/c/Users/asus/AppData/Local/Microsoft/WindowsApps:/snap/bin'

I am new to Linux and am not able to figure out what this error is. I have come to figure out it may be a problem with the bashrc file in OpenFOAM since the error appears only when I source it. Please help me. The bashrc file in Openfoam instalation folder is:

#----------------------------------*-sh-*------------------------------------ 
--
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
#   \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
#    \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
#---------------------------------------------------------------------------- 
 --
# License
#     This file is part of OpenFOAM, licensed under GNU General Public 
 License
#     <http://www.gnu.org/licenses/>.
#
# File
#     etc/bashrc
#
# Description
#     The OpenFOAM environment for POSIX shell (eg, bash,dash,zsh,...).
#     Source manually or from the ~/.bashrc or ~/.profile files.
#
#     Many settings can be overridden using a <prefs.sh> file:
#
#       - Base values (eg, from system admin):
#         -  $WM_PROJECT_DIR/etc/prefs.sh
#
#       - User or group values (first file found):
#         -  ~/.OpenFOAM/$WM_PROJECT_VERSION/prefs.sh
#         -  ~/.OpenFOAM/prefs.sh
#         -  $WM_PROJECT_SITE/site/$WM_PROJECT_VERSION/prefs.sh
#         -  $WM_PROJECT_SITE/site/prefs.sh
#
# Note: Changes made to this bashrc file may be lost with the next upgrade.
#------------------------------------------------------------------------------

export WM_PROJECT=OpenFOAM
export WM_PROJECT_VERSION=v1806

# [FOAM_INST_DIR] - parent directory containing the OpenFOAM installation.
# \- When this file is located as $WM_PROJECT_DIR/etc/bashrc, the next lines
#    should work when sourced by BASH or ZSH shells. If this however fails,
#    set one of the fallback values to an appropriate path.
# --
rc="${BASH_SOURCE:-${ZSH_NAME:+$0}}"
[ -n "$rc" ] && FOAM_INST_DIR=$(\cd $(dirname $rc)/../.. && \pwd -L) || \
FOAM_INST_DIR=$HOME/$WM_PROJECT
# FOAM_INST_DIR=/opt/$WM_PROJECT
# FOAM_INST_DIR=/usr/local/$WM_PROJECT
#
# END OF (NORMAL) USER EDITABLE PART
############################################################################
: # Extra safety - if the user commented out all fallback values
unset rc

# Configuration environment variables.
# Should override via <prefs.sh> file instead of editing this file.

# [WM_COMPILER_TYPE] - Compiler location:
# = system | ThirdParty
export WM_COMPILER_TYPE=ThirdParty

# [WM_COMPILER] - Compiler:
# = Gcc | Gcc4[8-9] | Gcc5[1-5] | Gcc6[1-4] | Gcc7[1-3] | Gcc8[1] | GccKNL |
#   Clang | Clang3[7-9] | Clang[4-6]0 | Icc | IccKNL | Cray | Arm
export WM_COMPILER=Gcc63
# [WM_ARCH_OPTION] - Memory addressing:
# = 32 | 64
#   * on a 64-bit OS this can be 32 or 64
#   * on a 32-bit OS, it is always 32-bit and this option is ignored
export WM_ARCH_OPTION=64

# [WM_PRECISION_OPTION] - Floating-point precision:
# = DP | SP
export WM_PRECISION_OPTION=DP

# [WM_LABEL_SIZE] - Label size in bits:
# = 32 | 64
export WM_LABEL_SIZE=32

# [WM_COMPILE_OPTION] - Optimised, debug, profiling:
# = Opt | Debug | Prof
export WM_COMPILE_OPTION=Opt

# [WM_MPLIB] - MPI implementation:
export WM_MPLIB=OPENMPI


#----------------------------------------------------------------------------
# (legacy / advanced)
#
# [FOAM_SIGFPE] - Trap floating-point exceptions.
#               - overrides the 'trapFpe' controlDict entry
# = true | false
#export FOAM_SIGFPE=true

# [FOAM_SETNAN] - Initialize memory with NaN
#               - overrides the 'setNaN' controlDict entry
# = true | false
#export FOAM_SETNAN=false

# [WM_OSTYPE] - Operating System Type:
# = POSIX
#export WM_OSTYPE=POSIX


############################################################################

# Old directories to be cleaned from PATH, LD_LIBRARY_PATH
foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
    $HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
    $WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN"

# Location of installation and third-party software
export WM_PROJECT_INST_DIR=$FOAM_INST_DIR
export WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/$WM_PROJECT-$WM_PROJECT_VERSION
export WM_THIRD_PARTY_DIR=$WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION

# [WM_PROJECT_SITE] - Location of site-specific (group) files
# default (unset) implies WM_PROJECT_INST_DIR/site
if [ -d "$WM_PROJECT_SITE" ]
then
    export WM_PROJECT_SITE
else
    unset WM_PROJECT_SITE
fi
# [WM_PROJECT_USER_DIR] - Location of user files
export WM_PROJECT_USER_DIR=$HOME/$WM_PROJECT/$USER-$WM_PROJECT_VERSION

# Load shell functions
. $WM_PROJECT_DIR/etc/config.sh/functions

# Overrides via <prefs.sh>
_foamEtc -mode=o  prefs.sh      # 1) other (system) values
_foamEtc -mode=ug prefs.sh      # 2) user or group values

# Evaluate command-line parameters and record settings for later.
# These can be used to set/unset values, specify additional files etc.
export FOAM_SETTINGS="$@"
_foamEval $@

# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PATH MANPATH LD_LIBRARY_PATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean LD_LIBRARY_PATH "$foamOldDirs"

# Setup for OpenFOAM compilation etc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config  settings

# Setup for third-party packages
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config  mpi
_foamEtc -config  paraview -- $@        # Pass through for evaluation
_foamEtc -config  vtk
_foamEtc -config  ensight
_foamEtc -config  gperftools
## _foamEtc -config  ADIOS
## _foamEtc -config  ADIOS2
_foamEtc -config  CGAL
_foamEtc -config  scotch
_foamEtc -config  FFTW

# Interactive shell
if /usr/bin/tty -s 2>/dev/null
then
    _foamEtc -config  aliases
    [ "${BASH_VERSINFO:-0}" -ge 4 ] && _foamEtc -config  bash_completion
fi


# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PATH MANPATH LD_LIBRARY_PATH

_foamClean PATH
_foamClean MANPATH
_foamClean LD_LIBRARY_PATH

# Add trailing ':' for system manpages
if [ -n "$MANPATH" ]
then
    MANPATH="${MANPATH}:"
fi

if [ -n "$LD_PRELOAD" ]
then
    export LD_PRELOAD
    _foamClean LD_PRELOAD
fi


# Cleanup temporary information
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Unload shell functions
. $WM_PROJECT_DIR/etc/config.sh/functions

# Variables (done as the last statement for a clean exit code)
unset FOAM_INST_DIR     # Old variable name (OpenFOAM-v1606) - now unneeded
unset cleaned foamOldDirs

#----------------------------------------------------------------------------
GRANZER
  • 355
  • 3
  • 13
  • Windows uses horrible file names with spaces, parentheses and other characters which have special meaning for bash. Surround those names with double quotes or even single quotes: PATH="...", or better PATH='...'. – linuxfan says Reinstate Monica Jul 15 '18 at 05:23
  • Your question is confusing. When you install Ubuntu within WSL, you have Bash by default, so I'm not sure what OpenFOAM has to do with it. You post your `PATH` variable, but it is **unquoted** and **spaces matter in Linux**. Either quote `PATH="...."` to avoid **word-splitting** and/or escape any whitespace and **parenthesis**, e.g. `Program\ Files\ \(x86\)`. (unescaped parenthesis are not allowed in path variables) – David C. Rankin Jul 15 '18 at 05:25
  • 1
    @linuxfan I am trying to setup OpenFOAM using WSL. I The PATH variable is not written by me its in the output of my terminal when I source the bashrc file in OpenFOAM to set up the OpenFOAM environment. – GRANZER Jul 15 '18 at 05:33
  • 1
    @DavidC.Rankin I am trying to setup OpenFOAM using WSL. I The PATH variable is not written by me its in the output of my terminal when I source the bashrc file in OpenFOAM to set up the OpenFOAM environment. – GRANZER Jul 15 '18 at 05:34
  • Is that line 38? The line generating the `eval` error? I suspect it is -- and for the exact reason I discuss, The `(...)` are not escaped an there are spaces in the `PATH`, You need to find where your `PATH` variable is stored (generally set in `/home/you/.bashrc` or `/home/you/.bash_profile` (or some use `.profile`) and make sure it is **quoted**. – David C. Rankin Jul 15 '18 at 05:39
  • The snippet you show is really bad: for example `/mnt/c/Program:Files:` looks wrong, the colons should be spaces. If bashrc contains that, you should modify it without worrying. PATH should contain a list of directories separated by colon. – linuxfan says Reinstate Monica Jul 15 '18 at 05:40
  • @linuxfan It looks like whatever openFOAM is doing it is replacing `spaces` with `':'`, but it does not catch the `(x86)` which is causing the `syntax error near unexpected token `('` error. (and now I know what openFOAM is -- and when I did years of fluid dynamics -- all I had was my HP28S or the Vax system in the days before C/C++ was even standardized (that trivia defines the exact year `:)` – David C. Rankin Jul 15 '18 at 05:41
  • May be it replaces spaces with colons trying to separate multiple names. But spaces, like parentheses, are in this case part of a SINGLE name. Quote them. – linuxfan says Reinstate Monica Jul 15 '18 at 05:47
  • 2
    Sounds like a bug in OpenFOAM's shell scripts. [This is one of them](https://github.com/OpenFOAM/OpenFOAM-dev/blob/8ca408bf6c83999c71db180f5b2f306472f20b5c/bin/foamCleanPath), and it's making the very common mistake of assuming that no filenames will ever contain spaces. Since you're running on Windows where spaces in filenames are common, you're triggering a bug. I would suggest you save yourself the trouble and install OpenFOAM in Hyper-V, VirtualBox or other VM instead. It should work way better on real Linux than on WSL. – that other guy Jul 15 '18 at 05:48
  • Adding a couple of quotes in bashrc is quick and will not hurt... – linuxfan says Reinstate Monica Jul 15 '18 at 05:56
  • @DavidC.Rankin the line 38 that is shown in the terminal output is is referring to the bashrc file in OpenFOAM I think (I have edited my question to include the content of this file) and not the .bashrc in $HOME. I have edited the .bashrc file in my $HOME to source the bashrc file (from OpenFOAM) whenever I start my terminal. bashrc file in OpenFOAM is used to set up the OpenFOAM enviornment I think, and the codes in this file is what is accessing the PATH variable. – GRANZER Jul 15 '18 at 06:18
  • @linuxfan code in bashrc or .bashrc dosnt contain the the line like /mnt/c/Program:Files: . I think the code in bashrc has a line which is accessing the PATH variable so the terminal is showing that output. – GRANZER Jul 15 '18 at 06:22
  • You must have somewhere a file containing PATH=.../mnt/c/Program\ Files..., or PATH=".../mnt/c/Program Files...". Anything different is an error. Then, some script tries to parse (or read) that file, and it fails. By quoting, or deleting the guilty parsing (maybe putting by hand what it fails to do) you should solve. – linuxfan says Reinstate Monica Jul 15 '18 at 06:27
  • Remove Windows path with [my method](https://stackoverflow.com/a/51345880/8928481). – Biswapriyo Jul 15 '18 at 06:35
  • Ok after some digging I am sure that the $PATH variable itself has correct entries without and colons replacing space. – GRANZER Jul 15 '18 at 08:10
  • Similar problem and solution as https://stackoverflow.com/questions/52782457/openfoam-win-10-ubuntu-bash-installing-fails/52833678#52833678 – Mark.O Oct 16 '18 at 12:44

2 Answers2

4

I'm not sure why the other response has been accepted as the correct solution. It is totally irrelevant to OpenFOAM. As I have explained here, WSL inherits Windows environment variables which have incompatible characters like spaces or parenthesis. This is a bug which I will try to report in their GitHub repo. but for the moment the workaround is to run the regedit program and find the below entry:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path

right click and modify it. Find all the parameters between two ; and put quotations "..." around the ones with incompatible characters, in this specific case parenthesis.

By the way it is a false alarm and it should not affect the compilation/functionality of OpenFOAM.

P.S. I have reported the issue here in WSL GitHub repository.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
0

It is because OpenFoam team set wrong default installation path in their bashrc. It is defaulted to $HOME where the installation guide in their site set it to /opt/.

You can fix this by commenting FOAM_INST_DIR=$HOME/$WM_PROJECT and uncomment FOAM_INST_DIR=/opt/$WM_PROJECT in the OpenFoam bashrc file.

rkta
  • 3,959
  • 7
  • 25
  • 37
grepsed
  • 24
  • 1
  • 1
    Sir/Madam this seems to be a wrong solution. I would appreciate if you could check it. if it is correct please support with valid documentation. Otherwise I have to flag and downvote to avoid confusion for other users. – Foad S. Farimani Sep 14 '18 at 12:38