LoginSignup
5
4

More than 3 years have passed since last update.

シェルスクリプト 実行方法

Last updated at Posted at 2019-11-15

以下のようなスクリプトがあった場合

hello-world.sh
#!/bin/bash
echo 'Hello World!'
スクリプトファイルとして実行
./hello-world.sh
  • シェバング行(#!/bin/bash)が必要
  • 実行属性が必要
  • 新しいシェル上で実行される
シェルの引数として実行
sh hello-world.sh
  • シェバング行(#!/bin/bash)が不要
  • 実行属性が不要
  • 新しいシェル上で実行される
標準入力として実行
sh -s < hello-world.sh
  • シェバング行(#!/bin/bash)が不要
  • 実行属性が不要
  • 新しいシェル上で実行される
. コマンドとして実行
. hello-world.sh
  • シェバング行(#!/bin/bash)が不要
  • 実行属性が不要
  • 現在のシェル上で実行される
5
4
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
5
4