0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

shell script が bash で起動されたかどうか判定する方法

Last updated at Posted at 2021-01-01

shell script が bash で起動されたかどうか判定する方法

sh ./check.sh のように sh を使って起動されるのを検出してエラー終了させたい。

スクリプト

check.sh

# !/bin/bash

if [ x$BASH_SOURCE = x"" ] ; then
    echo please run by $0 or bash $0 instead.
    exit 1
fi
echo OK: you are using bash.

実行例

$ sh ./check.sh 
please run by ./check.sh or bash ./check.sh instead.
$ ./check.sh 
OK: you are using bash.
$ bash ./check.sh 
OK: you are using bash.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?