Shell scriptを書くときに sh-bang(#!
)を記述することは多いが、ちょっと試してみた。
どこかでまとめるかも。
#! ./test.sh
# Configuration file for recipe
echo "Argument=$#" echo "Myname=$0" [ ! -z "$1" ] && echo "Arg[1] = $1" [ ! -z "$2" ] && echo "Arg[2] = $2"
んで、これを試す。
$ chmod +x test.sh recipe.sh $ ./recipe.sh
動かない。
調べてみた。
へぇ。shbangでshellscriptを呼び出せないのか…
ほほう。/usr/bin/envを利用すればなんとかなるのか。
#! /usr/bin/env ./test.sh
$ ./recipe.sh recipe.conf Argument=2 Myname=./test.sh Arg[1] = ./recipe.sh Arg[2] = recipe.conf
$0
に test.sh$1
に recipe.sh$2
に recipe.confなるほどね。
ちょっとPOSIX的に微妙だけど、仕方がないこととするか…