OpenFoam Win 10,Ubuntu Bash 安装失败
OpenFoam Win 10, Ubuntu Bash installing fails
我正在尝试在 Win 10 ubuntu bash 上安装 OpenFoam。我正在执行以下步骤:
OpenFoam installation on win 10 Ubuntu bash
在这一步
source $HOME/.bashrc
我收到以下错误:
-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_275852031:/mnt/c/Windows/System32:/mnt/c/DAYSIM/lib:/mnt/c/DAYSIM/bin:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:Files/Microsoft:SQL:Server/120/Tools/Binn:Files/Common:Files/Autodesk:Shared:/mnt/c/Radiance/bin:Server/130/Tools/Binn:Files/dotnet:Server/Client:SDK/ODBC/130/Tools/Binn:(x86)/Microsoft:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36/Scripts:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36:/mnt/c/Users/danie/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/danie/AppData/Local/Programs/Microsoft:VS:Code/bin:/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/daniel/OpenFOAM/daniel-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_275852031:/mnt/c/Windows/System32:/mnt/c/DAYSIM/lib:/mnt/c/DAYSIM/bin:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:Files/Microsoft:SQL:Server/120/Tools/Binn:Files/Common:Files/Autodesk:Shared:/mnt/c/Radiance/bin:Server/130/Tools/Binn:Files/dotnet:Server/Client:SDK/ODBC/130/Tools/Binn:(x86)/Microsoft:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36/Scripts:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36:/mnt/c/Users/danie/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/danie/AppData/Local/Programs/Microsoft:VS:Code/bin:/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/daniel/OpenFOAM/daniel-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_275852031:/mnt/c/Windows/System32:/mnt/c/DAYSIM/lib:/mnt/c/DAYSIM/bin:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:Files/Microsoft:SQL:Server/120/Tools/Binn:Files/Common:Files/Autodesk:Shared:/mnt/c/Radiance/bin:Server/130/Tools/Binn:Files/dotnet:Server/Client:SDK/ODBC/130/Tools/Binn:(x86)/Microsoft:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36/Scripts:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36:/mnt/c/Users/danie/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/danie/AppData/Local/Programs/Microsoft:VS:Code/bin:/snap/bin'
我不明白这里发生了什么。任何帮助将不胜感激。
OpenFoam bashrc代码如下:
#----------------------------------*-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:+[=13=]}}"
[ -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:
# = SYSTEMOPENMPI | OPENMPI | SYSTEMMPI | MPI | MPICH | MPICH-GM |
# HPMPI | CRAY-MPICH | FJMPI | QSMPI | SGIMPI | INTELMPI | USERMPI
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
#------------------------------------------------------------------------------
bash
(或您的 .bashrc
)无法处理包含未转义括号的 $PATH
。 Windows 默认情况下在其路径中有 C:\Program Files (x86)
,并且可能在 Linux 子系统下将其转换为 /mnt/c/Program Files (x86)
。一些糟糕的处理然后将其转换为(例如) /mnt/c/Program:Files:(x86)
,然后 bash
在括号中阻塞。
如果您显示 .bashrc
的相关行,也许可以找到修复。以下最有可能起作用:
export PATH="$PATH":/some/new/path
而不是
export PATH=$PATH:/some/new/path
更新
由于您的 .bashrc
正在获取另一个 bashrc
文件,因此问题出在另一个 bashrc
文件上。该文件无法处理空格。
另见
https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path
答案是 foamCleanPath 如何在 PATH 内部使用 IFS 拆分(使用空格)。这已经在当前的开发分支中进行了更改,更改类似于上一个(已删除的)答案。
此外,OpenFOAM 现在允许 cwd() 使用逻辑名称而不是物理名称,这提供了一种额外的方法来解决案例目录包含空格时的问题。
感谢@user10142377,问题已解决。 foamCleanPath 中的代码必须替换为以下代码:
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \ / O peration |
# \ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# foamCleanPath
#
# Description
# Usage: foamCleanPath [OPTION] path [filter] .. [filter]
# foamCleanPath [OPTION] -env=name [filter] .. [filter]
#
# Prints its argument (which should be a ':' separated path)
# without the following:
# - duplicate elements
# - elements matching the specified filter(s)
# - inaccessible directories (with the -strip option)
#
# Note
# - false matches possible when the filter contains '.' (sed regex) etc.
# - a single composite filter can be passed in. This composite filter
# is assumed to be delimited by whitespace, colons or semi-colons.
#
# Examples for cleaning the path:
#
# - Using explicit arguments
# cleaned=$(foamCleanPath "$PATH" dir1:dir2) && PATH=$cleaned
#
# - Variable to clean passed as an option
# cleaned=$(foamCleanPath -env=PATH dir1:dir2) && PATH=$cleaned
#
# - Using shell evaluation for the output
# eval $(foamCleanPath -sh=PATH $PATH" dir1:dir2)
# eval "$(foamCleanPath -sh=PATH -env=PATH dir1:dir2)"
# eval "$(foamCleanPath -sh-env=PATH dir1:dir2)"
#
# - Similarly for c-shell
# eval `foamCleanPath -csh-env=PATH dir1:dir2`
#
#------------------------------------------------------------------------------
usage() {
cat <<USAGE 1>&2
Usage: foamCleanPath [OPTION] path [filter] .. [filter]
foamCleanPath [OPTION] -env=name [filter] .. [filter]
options:
-csh=NAME Produce 'setenv NAME ...' output for csh eval
-sh=NAME Produce 'NAME=...' output for sh eval
-csh-env=NAME As per -csh, with -env for initial content
-sh-env=NAME As per -sh, with -env for initial content
-env=NAME Evaluate NAME to obtain initial content
-debug Print debug information to stderr
-strip Remove inaccessible directories
-verbose Report some progress (input, output, ...)
-help Print the usage
Prints its argument (which should be a ':' separated list) cleansed from
* duplicate elements
* elements whose start matches one of the filters
* inaccessible directories (the -strip option)
Exit status
0 on success
1 general error
2 initial value of 'path' is empty
USAGE
exit 1
}
# Report error and exit
die()
{
exec 1>&2
echo
echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " "; shift; done
echo
echo "See 'foamCleanPath -help' for usage"
echo
exit 1
}
#-------------------------------------------------------------------------------
# Input and outputs
unset dirList shellOutput
# Parse options
unset optDebug optEnvName optStrip optVerbose
while [ "$#" -gt 0 ]
do
case "" in
-h | -help*)
usage
;;
-csh=* | -sh=* | -csh-env=* | -sh-env=*)
name="${1#*=}"
[ -n "$name" ] || die "Option '' missing an ENVNAME"
# Output prefix
case "" in
-csh*)
shellOutput="setenv $name " # eg, "setenv PATH xyz"
;;
*)
shellOutput="$name=" # eg, "PATH=xyz"
;;
esac
# For (-csh-env | -sh-env) also use name for input evaluation
case "" in
*-env=*)
optEnvName="$name"
;;
esac
;;
-env=*)
name="${1#*=}"
[ -n "$name" ] || die "Option '' missing an ENVNAME"
optEnvName="$name"
;;
-debug)
optDebug=true
;;
-strip)
optStrip=true
;;
-verbose)
optVerbose=true
;;
*)
break
;;
esac
shift
done
# Basic checks
if [ -n "$optEnvName" ]
then
eval "dirList=$$optEnvName"
elif [ "$#" -ge 1 ]
then
dirList=""
shift
else
die "Requires at least one argument, or use the -env option"
fi
[ -n "$dirList" ] || exit 2 # Quick exit on empty 'dirList'
#-------------------------------------------------------------------------------
# Debugging (optional)
if [ -n "$optDebug" ]
then
printDebug() { while [ "$#" -ge 1 ]; do echo "" 1>&2; shift; done; }
else
printDebug() { true; } # No-op
fi
# Optional test for directory existence
if [ -n "$optStrip" ]
then
isDir() { test -d ""; } # Check for directory existence
else
isDir() { test -n ""; } # Only check for non-zero string
fi
# The "filter ... filterN" may have been passed as a single parameter
# or may contain ':' separators.
# Currently (OCT-2018) also accept split on whitespace too.
oldIFS="$IFS" # Preserve initial IFS
IFS=':; ' # Split on colon, semicolon, whitespace
set -- $*
if [ -n "$optVerbose" ]
then
echo "clean: $dirList" 1>&2
echo "with: $@" 1>&2
fi
printDebug "input>$dirList<"
# Apply filters via sed. Path and filter cannot contain '?'.
for filter
do
if [ -n "$filter" ]
then
printDebug "remove>$filter<"
dirList=$(echo "$dirList:" | sed -e "s?${filter}[^:]*:??g")
fi
done
printDebug "intermediate>$dirList<"
IFS=':' # Split on colon. No split on whitespace.
set -- $dirList
# Rebuild the list
unset dirList
for dir
do
printDebug "check>$dir< in $dirList"
if isDir "$dir"
then
# Detect duplicates (ie, dir already in the list)
duplicate=$(echo ":$dirList:" | sed -ne '\?:'"$dir"':?p')
if [ -n "$duplicate" ]
then
printDebug "duplicate>$dir<"
else
dirList="${dirList}${dirList:+:}$dir"
fi
fi
done
IFS="$oldIFS" # Restore initial IFS
printDebug "output>$dirList<"
if [ -n "$optVerbose" ]
then
echo "output: \"$dirList\"" 1>&2
fi
echo "$shellOutput\"$dirList\""
#------------------------------------------------------------------------------
可以在 OpenFoam 应用程序的 bin 文件夹中找到该文件。
This link 转到 OpenFoam 的 gitlab 中的原始讨论。
我正在尝试在 Win 10 ubuntu bash 上安装 OpenFoam。我正在执行以下步骤: OpenFoam installation on win 10 Ubuntu bash
在这一步
source $HOME/.bashrc
我收到以下错误:
-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_275852031:/mnt/c/Windows/System32:/mnt/c/DAYSIM/lib:/mnt/c/DAYSIM/bin:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:Files/Microsoft:SQL:Server/120/Tools/Binn:Files/Common:Files/Autodesk:Shared:/mnt/c/Radiance/bin:Server/130/Tools/Binn:Files/dotnet:Server/Client:SDK/ODBC/130/Tools/Binn:(x86)/Microsoft:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36/Scripts:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36:/mnt/c/Users/danie/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/danie/AppData/Local/Programs/Microsoft:VS:Code/bin:/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/daniel/OpenFOAM/daniel-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_275852031:/mnt/c/Windows/System32:/mnt/c/DAYSIM/lib:/mnt/c/DAYSIM/bin:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:Files/Microsoft:SQL:Server/120/Tools/Binn:Files/Common:Files/Autodesk:Shared:/mnt/c/Radiance/bin:Server/130/Tools/Binn:Files/dotnet:Server/Client:SDK/ODBC/130/Tools/Binn:(x86)/Microsoft:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36/Scripts:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36:/mnt/c/Users/danie/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/danie/AppData/Local/Programs/Microsoft:VS:Code/bin:/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/daniel/OpenFOAM/daniel-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_275852031:/mnt/c/Windows/System32:/mnt/c/DAYSIM/lib:/mnt/c/DAYSIM/bin:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:Files/Microsoft:SQL:Server/120/Tools/Binn:Files/Common:Files/Autodesk:Shared:/mnt/c/Radiance/bin:Server/130/Tools/Binn:Files/dotnet:Server/Client:SDK/ODBC/130/Tools/Binn:(x86)/Microsoft:Server/140/Tools/Binn:Server/140/DTS/Binn:Server/140/Tools/Binn/ManagementStudio:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36/Scripts:/mnt/c/Users/danie/AppData/Local/Programs/Python/Python36:/mnt/c/Users/danie/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/danie/AppData/Local/Programs/Microsoft:VS:Code/bin:/snap/bin'
我不明白这里发生了什么。任何帮助将不胜感激。
OpenFoam bashrc代码如下:
#----------------------------------*-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:+[=13=]}}"
[ -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:
# = SYSTEMOPENMPI | OPENMPI | SYSTEMMPI | MPI | MPICH | MPICH-GM |
# HPMPI | CRAY-MPICH | FJMPI | QSMPI | SGIMPI | INTELMPI | USERMPI
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
#------------------------------------------------------------------------------
bash
(或您的 .bashrc
)无法处理包含未转义括号的 $PATH
。 Windows 默认情况下在其路径中有 C:\Program Files (x86)
,并且可能在 Linux 子系统下将其转换为 /mnt/c/Program Files (x86)
。一些糟糕的处理然后将其转换为(例如) /mnt/c/Program:Files:(x86)
,然后 bash
在括号中阻塞。
如果您显示 .bashrc
的相关行,也许可以找到修复。以下最有可能起作用:
export PATH="$PATH":/some/new/path
而不是
export PATH=$PATH:/some/new/path
更新
由于您的 .bashrc
正在获取另一个 bashrc
文件,因此问题出在另一个 bashrc
文件上。该文件无法处理空格。
另见
https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path
答案是 foamCleanPath 如何在 PATH 内部使用 IFS 拆分(使用空格)。这已经在当前的开发分支中进行了更改,更改类似于上一个(已删除的)答案。
此外,OpenFOAM 现在允许 cwd() 使用逻辑名称而不是物理名称,这提供了一种额外的方法来解决案例目录包含空格时的问题。
感谢@user10142377,问题已解决。 foamCleanPath 中的代码必须替换为以下代码:
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \ / O peration |
# \ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# foamCleanPath
#
# Description
# Usage: foamCleanPath [OPTION] path [filter] .. [filter]
# foamCleanPath [OPTION] -env=name [filter] .. [filter]
#
# Prints its argument (which should be a ':' separated path)
# without the following:
# - duplicate elements
# - elements matching the specified filter(s)
# - inaccessible directories (with the -strip option)
#
# Note
# - false matches possible when the filter contains '.' (sed regex) etc.
# - a single composite filter can be passed in. This composite filter
# is assumed to be delimited by whitespace, colons or semi-colons.
#
# Examples for cleaning the path:
#
# - Using explicit arguments
# cleaned=$(foamCleanPath "$PATH" dir1:dir2) && PATH=$cleaned
#
# - Variable to clean passed as an option
# cleaned=$(foamCleanPath -env=PATH dir1:dir2) && PATH=$cleaned
#
# - Using shell evaluation for the output
# eval $(foamCleanPath -sh=PATH $PATH" dir1:dir2)
# eval "$(foamCleanPath -sh=PATH -env=PATH dir1:dir2)"
# eval "$(foamCleanPath -sh-env=PATH dir1:dir2)"
#
# - Similarly for c-shell
# eval `foamCleanPath -csh-env=PATH dir1:dir2`
#
#------------------------------------------------------------------------------
usage() {
cat <<USAGE 1>&2
Usage: foamCleanPath [OPTION] path [filter] .. [filter]
foamCleanPath [OPTION] -env=name [filter] .. [filter]
options:
-csh=NAME Produce 'setenv NAME ...' output for csh eval
-sh=NAME Produce 'NAME=...' output for sh eval
-csh-env=NAME As per -csh, with -env for initial content
-sh-env=NAME As per -sh, with -env for initial content
-env=NAME Evaluate NAME to obtain initial content
-debug Print debug information to stderr
-strip Remove inaccessible directories
-verbose Report some progress (input, output, ...)
-help Print the usage
Prints its argument (which should be a ':' separated list) cleansed from
* duplicate elements
* elements whose start matches one of the filters
* inaccessible directories (the -strip option)
Exit status
0 on success
1 general error
2 initial value of 'path' is empty
USAGE
exit 1
}
# Report error and exit
die()
{
exec 1>&2
echo
echo "Error encountered:"
while [ "$#" -ge 1 ]; do echo " "; shift; done
echo
echo "See 'foamCleanPath -help' for usage"
echo
exit 1
}
#-------------------------------------------------------------------------------
# Input and outputs
unset dirList shellOutput
# Parse options
unset optDebug optEnvName optStrip optVerbose
while [ "$#" -gt 0 ]
do
case "" in
-h | -help*)
usage
;;
-csh=* | -sh=* | -csh-env=* | -sh-env=*)
name="${1#*=}"
[ -n "$name" ] || die "Option '' missing an ENVNAME"
# Output prefix
case "" in
-csh*)
shellOutput="setenv $name " # eg, "setenv PATH xyz"
;;
*)
shellOutput="$name=" # eg, "PATH=xyz"
;;
esac
# For (-csh-env | -sh-env) also use name for input evaluation
case "" in
*-env=*)
optEnvName="$name"
;;
esac
;;
-env=*)
name="${1#*=}"
[ -n "$name" ] || die "Option '' missing an ENVNAME"
optEnvName="$name"
;;
-debug)
optDebug=true
;;
-strip)
optStrip=true
;;
-verbose)
optVerbose=true
;;
*)
break
;;
esac
shift
done
# Basic checks
if [ -n "$optEnvName" ]
then
eval "dirList=$$optEnvName"
elif [ "$#" -ge 1 ]
then
dirList=""
shift
else
die "Requires at least one argument, or use the -env option"
fi
[ -n "$dirList" ] || exit 2 # Quick exit on empty 'dirList'
#-------------------------------------------------------------------------------
# Debugging (optional)
if [ -n "$optDebug" ]
then
printDebug() { while [ "$#" -ge 1 ]; do echo "" 1>&2; shift; done; }
else
printDebug() { true; } # No-op
fi
# Optional test for directory existence
if [ -n "$optStrip" ]
then
isDir() { test -d ""; } # Check for directory existence
else
isDir() { test -n ""; } # Only check for non-zero string
fi
# The "filter ... filterN" may have been passed as a single parameter
# or may contain ':' separators.
# Currently (OCT-2018) also accept split on whitespace too.
oldIFS="$IFS" # Preserve initial IFS
IFS=':; ' # Split on colon, semicolon, whitespace
set -- $*
if [ -n "$optVerbose" ]
then
echo "clean: $dirList" 1>&2
echo "with: $@" 1>&2
fi
printDebug "input>$dirList<"
# Apply filters via sed. Path and filter cannot contain '?'.
for filter
do
if [ -n "$filter" ]
then
printDebug "remove>$filter<"
dirList=$(echo "$dirList:" | sed -e "s?${filter}[^:]*:??g")
fi
done
printDebug "intermediate>$dirList<"
IFS=':' # Split on colon. No split on whitespace.
set -- $dirList
# Rebuild the list
unset dirList
for dir
do
printDebug "check>$dir< in $dirList"
if isDir "$dir"
then
# Detect duplicates (ie, dir already in the list)
duplicate=$(echo ":$dirList:" | sed -ne '\?:'"$dir"':?p')
if [ -n "$duplicate" ]
then
printDebug "duplicate>$dir<"
else
dirList="${dirList}${dirList:+:}$dir"
fi
fi
done
IFS="$oldIFS" # Restore initial IFS
printDebug "output>$dirList<"
if [ -n "$optVerbose" ]
then
echo "output: \"$dirList\"" 1>&2
fi
echo "$shellOutput\"$dirList\""
#------------------------------------------------------------------------------
可以在 OpenFoam 应用程序的 bin 文件夹中找到该文件。 This link 转到 OpenFoam 的 gitlab 中的原始讨论。