LoginSignup
0
2

More than 5 years have passed since last update.

bash > 実行時引数 > --debugがついているかのチェック > ifとechoとgrep

Last updated at Posted at 2017-10-16
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv

概要

bashスクリプト実行時、--debugを付けたときだけ別処理をしたい。
例として、4時間30分かかるデータ処理をする前に、1つのファイルだけの処理で完了し、チェックをしたい。

参考

answered Dec 17 '10 at 5:38
dietbuddha

上記のコードを使わせていただく。

code

check_runtimeparameter_171016_exec
#!/usr/bin/env bash

TARGET="\-\-debug"  # --debug

if echo $@ | grep -q $TARGET; then
    echo "matched"
else
    echo "no match"
fi
$ bash check_runtimeparameter_171016_exec -parr2 --debug -param1
matched
$ bash check_runtimeparameter_171016_exec -parr2 --debuk -param1
no match

備考

きちんとした実行時引数の解析の場合は、以下のリンク先などが参考になりそうです。
自分がやりたいことはそこまでのことでないので上記程度で目的は果たせそうです。

関連: bash によるオプション解析
関連: bashで長いオプション解析をするためのスクリプト

検索用キーワード

(追記 2018/03/12)

  • DEBUG_OPT
    • 自分の実装で使っている変数名
0
2
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
0
2