下面這段怎麼改寫成Shell?
set i=-1
if %ComputerName%==AAA set Parameter_file=..\parameter\edw002m_parameterD.txt
if %ComputerName%==BBB set Parameter_file=..\parameter\edw002m_parameterU.txt
if %ComputerName%==CCC set Parameter_file=..\parameter\edw002m_parameterP.txt
if %ComputerName%==DDD set Parameter_file=..\parameter\edw002m_parameterP.txt
echo %Parameter_file%
echo %data% %time% > %LOG_FILE%
echo %ComputerName% >> %LOG_FILE%
for /f "delims=" %%a in ('more ^< %Parameter_file%') do (
set/a i+=1 & for /f %%z in ('echo/%%i%%') do (
if "%%z"=="0" set MSSQL_NAME=%%a
if "%%z"=="1" set MSSQL_USER=%%a
if "%%z"=="2" set MSSQL_PWD=%%a
if "%%z"=="3" set EVOICE_SERVER=%%a
)
)
.sh檔的使用說明(英文的)
https://www.gnu.org/software/bash/manual/bash.html
.sh 檔的第一行必須宣告
#!/bin/bash
Linux下應該沒有ComputerName這個環境變數,要自己抓
ComputerName=$(hostname)
(草稿沒測過)...(批次檔的迴圈部分有點忘了)
#!/bin/bash
LOG_FILE=TEST.LOG
i=-1
ComputerName=$(hostname)
case $ComputerName in
AAA) Parameter_file=../parameter/edw002m_parameterD.txt
;;
BBB) Parameter_file=../parameter/edw002m_parameterU.txt
;;
CCC) Parameter_file=../parameter/edw002m_parameterP.txt
;;
DDD) Parameter_file=../parameter/edw002m_parameterP.txt
;;
esac
echo $Parameter_file
now=$(date)
echo $now > $LOG_FILE
echo $ComputerName >> $LOG_FILE
for LINE in $(cat $Parameter_file)
do
i=$((i+1))
case $i in
0) MSSQL_NAME=$LINE
;;
1) MSSQL_USER=$LINE
;;
2) MSSQL_PWD=$LINE
;;
3) EVOICE_SERVER=$LINE
;;
esac
done