4
4

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 5 years have passed since last update.

shellの$1とかのスコープ確認

Posted at

シェルスクリプトに渡された引数を取るときと関数の引数を取るときどちらも「$1」を使うので、引数のスコープがどこまでになってるかをチェック。(関数の中の$1がシェルスクリプトで渡されたものになってないかが心配だった)

結果、関数の中の$1はちゃんと関数に渡された引数でした。

hello.sh
# /bin/sh

hello() {
  echo "Hello $1"
}

NAME=$1
hello "Mr.$1"
実行結果
$ sh hello.sh kamatama41
Hello Mr.kamatama41
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?