転載・引用について

ユーザ用ツール

サイト用ツール


tweet:2019:0201_01
no way to compare when less than two revisions

差分

このページの2つのバージョン間の差分を表示します。


tweet:2019:0201_01 [2019/02/01 16:48] (現在) – 作成 seirios
行 1: 行 1:
 +====== shbang ======
  
 +Shell scriptを書くときに sh-bang(''#!'')を記述することは多いが、ちょっと試してみた。
 +
 +どこかでまとめるかも。
 +
 +<code bash recipie.sh>
 +#! ./test.sh
 +</code>
 +
 +<code bash recipe.conf>
 +# Configuration file for recipe
 +</code>
 +
 +<code bash test.sh>
 +echo "Argument=$#"
 +
 +echo "Myname=$0"
 +[ ! -z "$1" ] && echo "Arg[1] = $1"
 +[ ! -z "$2" ] && echo "Arg[2] = $2"
 +</code>
 +
 +んで、これを試す。
 +
 +<code>
 +$ chmod +x test.sh recipe.sh
 +$ ./recipe.sh
 +</code>
 +
 +動かない。
 +
 +調べてみた。
 +  * [[http://myfuturesightforpast.blogspot.com/2017/01/what-is-shebang-binsh-in-posix-shell.html]]
 +へぇ。shbangでshellscriptを呼び出せないのか...
 +  * [[https://qiita.com/ngyuki/items/8d2a4a203087221bfafd]]
 +ほほう。/usr/bin/envを利用すればなんとかなるのか。
 +
 +<code bash recipie.sh>
 +#! /usr/bin/env ./test.sh
 +</code>
 +
 +<code>
 +$ ./recipe.sh recipe.conf
 +Argument=2
 +Myname=./test.sh
 +Arg[1] = ./recipe.sh
 +Arg[2] = recipe.conf
 +</code>
 +  * ふむ。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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki