2
3

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.

シェルスクリプト

Posted at

Pythonを触り始めて2年。なんとかシェルスクリプトから逃げていましたがついに逃げられなくなりました。

以下奮闘記です。

1.現在地を知りたい

SCRIPT_DIR=$(cd $(dirname $0); pwd)

$0は実行ファイルのパスを返してくれます。

2.現在地の親ディレクトリのパスを知りたい

PAR_DIR=$(cd $(dirname $0); cd ../; pwd)

3.入力を受け付けたい

input.sh
input1 = $1
input2 = $2

bash input.sh inp1 inp2
$NがN番目の引数になります。

4.変数を使いたい

FILENAME = $1
SCRIPT_DIR = $(cd $(dirname $FILENAME); pwd)
echo 'path for ${FILENAME} is ${SCRIPT_DIR}'

やっていることは1.と同じですね。

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?