shellscript 変数のスコープについて
Shellscriptの変数スコープと関数ついて。
関数に変数を渡すときに引数で渡して、その関数内では $1
で使うと思ってた。
#!/bin/bash set -eu _output() { echo "$1" } main() { local MESSAGE="hello world" _output "$MESSAGE" } main
main
関数内で定義した $MESSAGE
変数は _output
関数内で使えた。
#!/bin/bash set -eu _output() { echo "$MESSAGE" } main() { local MESSAGE="hello world" _output } main
ファイルの実行(bashとsh。他は知らん)
$ bash ./script.sh hello world
VSCodeでShellscript書くときにおすすめな拡張機能