LoginSignup
2
6

More than 5 years have passed since last update.

bashで「あの変数どこで定義されてるんだああああウギギギギギ」って時の対処法

Last updated at Posted at 2017-04-17

以下のスクリプトを実行する。

log.sh
#!/bin/bash

# via. http://qiita.com/kawaz/items/65cdbeaa739c4e6b7776
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME:+$FUNCNAME(): }'

bash -lx -c 'echo 1' 2> xtrace.log
$ ./log.sh

後は、grep export xtrace.logするなり何なり。

$ grep export xtrace.log
+(/etc/profile:4): eval 'PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/takumiabe/.rbenv/shims:/Users/takumiabe/.rbenv/bin:/Users/takumiabe/go/bin:~/dot_files
/bin:/usr/local/sbin:/usr/local/opt/coreutils/libexec/gnubin";' export 'PATH;'
++(/etc/profile:4): export PATH
+(/Users/takumiabe/.bash_profile:4): export 'PS1=[ \[\e[32m\]\u@\h:\w\[\e[0m\] ]\[\e[0;31m\]$(__git_ps1)\[\e[0m\] \n\$ '
+(/Users/takumiabe/.bash_profile:11): export HISTCONTROL=ignoredups:ignorespace
+(/Users/takumiabe/.bash_profile:13): export HISTSIZE=2000
...

参考:
PS4の設定でシェルスクリプトのデバッグが捗る http://qiita.com/kawaz/items/65cdbeaa739c4e6b7776

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