tweet:2019:0201_01
shbang
Shell scriptを書くときに sh-bang(#!
)を記述することは多いが、ちょっと試してみた。
どこかでまとめるかも。
- recipie.sh
#! ./test.sh
- recipe.conf
# Configuration file for recipe
- test.sh
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を利用すればなんとかなるのか。
- recipie.sh
#! /usr/bin/env ./test.sh
$ ./recipe.sh recipe.conf Argument=2 Myname=./test.sh Arg[1] = ./recipe.sh Arg[2] = recipe.conf
- ふむ。FreeBSDの/bin/shとbashは、envかませばなんとかなるのか。
$0
に test.sh$1
に recipe.sh$2
に recipe.conf
なるほどね。
ちょっとPOSIX的に微妙だけど、仕方がないこととするか…
tweet/2019/0201_01.txt · 最終更新: 2019/02/01 16:48 by seirios