シェルスクリプトのプロセスIDについて実験していると#!/bin/bash(sheBang)を書かないとプロセスIDが発行されない事に気付きました。例えば、以下のような例です。
■noSheBang.sh
bash
1shellName=${0##*/} 2shellNameWithOutEx=${shellName%.*} 3 4resultOfPgrep=`pgrep ${shellNameWithOutEx}` 5 6if test -n "${resultOfPgrep}" 7then 8 echo "ProcessID of me is ${resultOfPgrep}" 9else 10 echo "ProcessID was not issued to me " 11fi 12
■SheBang.sh(noSheBang.shにsheBangを追加しただけ)
bash
1#!/bin/bash 2shellName=${0##*/} 3shellNameWithOutEx=${shellName%.*} 4 5resultOfPgrep=`pgrep ${shellNameWithOutEx}` 6 7if test -n "${resultOfPgrep}" 8then 9 echo "ProcessID of me is ${resultOfPgrep}" 10else 11 echo "ProcessID was not issued to me " 12fi 13
■実行結果
XXXX# ./noSheBang.sh
ProcessID was not issued to me
XXXX# ./SheBang.sh
ProcessID of me is 5257
XXXX#
果たして、sheBangはシェルスクリプト実行時にどのような役割を果たしているのでしょうか?どなたか、シェルスクリプトが実行される仕組みと絡めてご説明いただけないでしょうか?
よろしくお願いいたします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/12 03:12
2017/02/12 03:48
2017/02/12 03:58