为了完成安装,我需要获取以下.sh文件:
function addvar () {
local tmp="${!1}" ;
tmp="${tmp//:${2}:/:}" ; tmp="${tmp/#${2}:/}" ; tmp="${tmp/%:${2}/}" ;
export $1="${2}:${tmp}" ;
}
if [ -z "${PATH}" ]; then
PATH=/share/MontePython/plc-2.0/bin
export PATH
else
addvar PATH /share/MontePython/plc-2.0/bin
fi
if [ -z "${PYTHONPATH}" ]; then
PYTHONPATH=/share/MontePython/plc-2.0/lib/python2.7/site-packages
export PYTHONPATH
else
addvar PYTHONPATH /share/MontePython/plc-2.0/lib/python2.7/site-packages
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/ipp/../compiler/lib/intel64
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/ipp/../compiler/lib/intel64
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/compiler/lib/intel64/
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/compiler/lib/intel64/
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/compiler/lib/intel64
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/compiler/lib/intel64
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/lib64
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /lib64
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/lib
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /lib
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/ipp/../compiler/lib/intel64/
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /share/apps/intel/l_ics_2015.1.133/composer_xe_2015.1.133/ipp/../compiler/lib/intel64/
fi
if [ -z "${LD_LIBRARY_PATH}" ]; then
LD_LIBRARY_PATH=/share/MontePython/plc-2.0/lib
export LD_LIBRARY_PATH
else
addvar LD_LIBRARY_PATH /share/MontePython/plc-2.0/lib
fi
CLIK_PATH=/share/MontePython/plc-2.0
export CLIK_PATH
CLIK_DATA=/share/MontePython/plc-2.0/share/clik
export CLIK_DATA
CLIK_PLUGIN=rel2015
export CLIK_PLUGIN
但是当我采购它时,我收到以下错误:
() not correctly positioned
知道为什么吗? 奇怪的是,当我在群集上操作时会发生这种错误,而我的PC上却没有。
编辑:
lsb_release -a
的输出是:
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.9 (Final)
Release: 6.9
Codename: Final
echo $0
的输出为-tcsh
。
答案 0 :(得分:3)
我认为你使用的是另一个shell(tcsh)而不是sh或bash。很可能你必须调整源代码以使用tcsh加载它。在sh / bash下工作正常
root@pve1:~# echo $0
-bash
答案 1 :(得分:1)
在bash
中,您的脚本在语法上是正确的。但是,如果您使用sh
,则会出现一些错误。检查shellcheck
输出:
$ shellcheck script.sh
In script.sh line 3:
function addvar () {
^-- SC2112: 'function' keyword is non-standard. Delete it.
In script.sh line 4:
local tmp="${!1}" ;
^-- SC2039: In POSIX sh, 'local' is undefined.
^-- SC2039: In POSIX sh, indirect expansion is undefined.
In script.sh line 5:
tmp="${tmp//:${2}:/:}" ; tmp="${tmp/#${2}:/}" ; tmp="${tmp/%:${2}/}" ;
^-- SC2039: In POSIX sh, string replacement is undefined.
^-- SC2039: In POSIX sh, string replacement is undefined.
^-- SC2039: In POSIX sh, string replacement is undefined.
总结:
function
关键字不需要(甚至不推荐)local
不支持sh
{li> ${//}
sh