2017-07-04 73 views
0

爲了完成安裝,我需要源的以下sh文件:錯誤而採購shell腳本

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 

任何想法爲什麼? 奇怪的是,當我在一個集羣上操作時,發生了這個錯誤,而我的電腦上沒有它。

編輯:

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

你使用的是什麼linux發行版?什麼類型的集羣?我可以在沒有任何問題的情況下在CentOS 6.x和7.x上發佈它,也可以在Promox上發佈(但沒有集羣) –

+0

您是否在使用'bash'或'sh'出現錯誤?你爲他們兩人貼了標籤,但他們不一樣 –

+0

@BogdanStoica我編輯帖子回答問題 – johnhenry

回答

3

我想你正在使用不同的shell(tcsh)而不是sh或bash。很可能你必須修改你的源代碼才能使用tcsh加載它。在sh/bash下正常工作

[email protected]:~# echo $0 
-bash 
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在POSIX不支持sh
  • 字符串替換${//}不支持sh
+0

我應該強迫它與bash一起使用嗎?如果是,如何? – johnhenry

+1

由於你正在採購腳本,你必須**從'bash' **中獲取它。 – randomir

+0

puttin#!/ bin/bash在腳本的開頭? – johnhenry