shell混用引發的任務無法啟動

2021-08-26 04:58:42 字數 1355 閱讀 9512

今天在使用debian 腳步啟動乙個sh時一直報錯,由此引發此文的形成:

在使用bash shell時,我們有這樣的場景:

env.sh -- 定義公共的變數

run1.sh -- 定義執行**

run2.sh -- 定義執行**

如果env.sh中的內容是根據具體的run*.sh作變化,那麼就需要給env.sh中傳入變數。

很多人可能會採用這種方式,

場景模擬:

env.sh:

#!/bin/sh echo $1

run1.sh:

#!/bin/sh current_path='core' echo $ . /home/admin/tmp/madding.lip/env.sh $current_path echo "invoke $current_path-service $1" if [ "$1" = "stop" ] ; then echo "`date`:stop --------------------------------" echo "remove $shutdownfile" elif [ "$1" = "debug" ] ; then echo "`date`:debug --------------------------------" fi

執行命令:

sh run.sh start

結果:在redhat 5.3中:

core

core

invoke core-service

debian 6:

core

start

invoke core-service

分析:表面現象問題出在:

. /home/admin/tmp/madding.lip/env.sh $current_path

根本:debian預設使用的:

madding@wmmad:~$ which sh /bin/sh madding@wmmad:~$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 jun 6 05:49 /bin/sh -> dash

redhat預設sh使用:

[admin@**** ~]$ which sh /bin/sh [admin@**** ~]$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 nov 16 2010 /bin/sh -> bash

處理意見:

1.shell盡量用各個都相容的方式書寫,這樣可移植性比較強

2.如果明確使用的shell,盡量在頭部表明,這樣執行./方式執行時能識別具體的shell

3.如果用具體的shell加腳步方式執行的話,建議明確shell腳步的解析器,如dash xx.sh 或者 bash xx.sh

shell混用引發的任務無法啟動

今天在使用debian 腳步啟動乙個sh時一直報錯,由此引發此文的形成 在使用bash shell時,我們有這樣的場景 env.sh 定義公共的變數 run1.sh 定義執行 run2.sh 定義執行 如果env.sh中的內容是根據具體的run sh作變化,那麼就需要給env.sh中傳入變數。很多人...

某個開機自啟的服務無法啟動導致系統無法啟動故障解決

cd etc init.d vim testsrv 輸入以下內容 bin bash chkconfig 2345 99 00 description this service is used for test case 1in start echo the service is started to...

利用shell開發sentinel的啟停指令碼

root node21 tree p data sentinel 26379 data sentinel 26379 drwxr xr x conf 存放sentinel的配置檔案 drwxr xr x logs 存放sentinel的日誌檔案 drwxr xr x run 存放sentinel的p...