LoginSignup
0
0

More than 5 years have passed since last update.

bash > debug > echo + redirectionにおいてredirectionの文字列がbash -xで表示されない > Link: 対処方法 (kshを使う)

Last updated at Posted at 2018-01-19
動作環境
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.9を使用。
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)
ksh version         sh (AT&T Research) 93u+ 2012-08-01

関連:bash > readonly > manとサンプルコード | bash -x実行時の表示

codeとdebug実行

#!/usr/bin/env bash 

set -eu # for safety

readonly DST_FILE='info_180119.txt'

echo "hello" > $DST_FILE

DST_FILE='dummy_180119.txt'

echo "hello" > $DST_FILE
run
$ bash -x debug_print_180119_exec 
+ set -eu
+ readonly DST_FILE=info_180119.txt
+ DST_FILE=info_180119.txt
+ echo hello
+ DST_FILE=dummy_180119.txt
debug_print_180119_exec: line 9: DST_FILE: readonly variable

上記の気になった点として、echo "hello" > $DST_FILEの部分は+ echo helloにデバッグ出力される。
どのファイルに書き出ししたのか、標準出力なのか、がデバッグ出力から分からない。

対処方法

色々書かれているが、

answered Jul 4 '13 at 22:56
ack

による「You, ksh使っちゃいなよ」が気になった。

EDIT: If Bash-specific features are not required, and backwards compatibility with the Bourne shell will do, the Korn shell (ksh, tested with version 93u+ 2012-08-01) does a bit better on showing information for redirects:

run
$ ksh -x debug_print_180119_exec 
+ set -eu
+ DST_FILE=info_180119.txt
+ readonly DST_FILE
+ echo hello
+ 1> info_180119.txt
debug_print_180119_exec: line 9: DST_FILE: is read only

info_180119.txtへ出力されている様子が分かるようになった。

kshはどれくらいbashの互換があるかはよくわからない。
bash特有の機能がある場合は使えないでしょう、とのこと。

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