LoginSignup
1
1

More than 5 years have passed since last update.

bash > set -eu > diffの実行から下の処理が実行されない > diffのexit codeが異なるため | no_exit_diff()関数を用意する

Last updated at Posted at 2018-02-28
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
NCAR Command Language Version 6.3.0
for WRF3.7.1, WPS3.7.1
  openmpi-1.8.x86_64 とその-devel
  mpich.x86_64 3.1-5.el6とその-devel
  gcc version 4.4.7 (とgfortran)
for WRF3.9, WPS3.9
  Open MPI v2.1.1
  gcc version 4.9.2 (とgfortran; devtoolset-3使用)
 NetCDF v4.4.1.1, NetCDF (Fortran API) v4.4.4
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
date (GNU coreutils) 8.4 
tmux 1.6-3.el6

概要

bashで指定するset -eu。エラー動作の観点からつけておくことが良いと思われる。

diffの実行から下の処理が実行されない症状に出会った。

データ

$ cat dat1.txt 
LON 135.0
LAT 35.0
$ cat dat2.txt 
LON 135.0
LAT 34.0
$ cat new_lon.txt 
LON 136.0
LAT 35.0

code

set -euあり

patch_lon_180228_exec
#!/usr/bin/env bash
set -eu

diff dat1.txt new_lon.txt > diff_lon

for elem in $(ls)
do
  echo $elem
done
$ bash patch_lon_180228_exec

lsの処理が実行されない。

set -euなし

patch_lon_180228_exec
#!/usr/bin/env bash
#set -eu

diff dat1.txt new_lon.txt > diff_lon

for elem in $(ls)
do
  echo $elem
done
$ bash patch_lon_180228_exec 
dat1.txt
dat2.txt
diff_lon
new_lon.txt
patch_lon_180228_exec

lsの処理が実行される。

diffのexit codeが異なるため

@tukiyo3 さんのコメントにてdiffのexit codeが異なるために上記となっていることを知りました。

情報感謝です。

さらに追加でいただいた情報を参考にno_exit_diff()関数を用意する案を考えました。

1
1
8

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
1
1