Skip to main content
added 2 characters in body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Along the lines of Stéphane's similar answer, here's a way to run an interactive bash shell in trace mode (running the single command exit), piped to a grep that shows only the source and alias commands; the source command immediately above the alias of interest should be the file that contains the alias command.

bash -ix -c exit 2>&1 |grep| grep -E 'source | \. |alias '

An instrumented run:

$ tail -1 ~/.bashrc
[ -f /tmp/a.bashrc ] && source /tmp/a.bashrc
$ cat /tmp/a.bashrc
[ -f /tmp/b.bashrc ] && source. /tmp/b.bashrc
$ cat /tmp/b.bashrc
alias answer='echo 42'

$ bash -ix -c exit 2>&1 |grep| grep -E 'source | \. |alias '
+ alias 'ls=ls --color=auto'
+ source /tmp/a.bashrc
++ source. /tmp/b.bashrc
+++ alias 'answer=echo 42'

Along the lines of Stéphane's similar answer, here's a way to run an interactive bash shell in trace mode (running the single command exit), piped to a grep that shows only the source and alias commands; the source command immediately above the alias of interest should be the file that contains the alias command.

bash -ix -c exit 2>&1 |grep -E 'source |alias '

An instrumented run:

$ tail -1 ~/.bashrc
[ -f /tmp/a.bashrc ] && source /tmp/a.bashrc
$ cat /tmp/a.bashrc
[ -f /tmp/b.bashrc ] && source /tmp/b.bashrc
$ cat /tmp/b.bashrc
alias answer='echo 42'

$ bash -ix -c exit 2>&1 |grep -E 'source |alias '
+ alias 'ls=ls --color=auto'
+ source /tmp/a.bashrc
++ source /tmp/b.bashrc
+++ alias 'answer=echo 42'

Along the lines of Stéphane's similar answer, here's a way to run an interactive bash shell in trace mode (running the single command exit), piped to a grep that shows only the source and alias commands; the source command immediately above the alias of interest should be the file that contains the alias command.

bash -ix -c exit 2>&1 | grep -E 'source | \. |alias '

An instrumented run:

$ tail -1 ~/.bashrc
[ -f /tmp/a.bashrc ] && source /tmp/a.bashrc
$ cat /tmp/a.bashrc
[ -f /tmp/b.bashrc ] && . /tmp/b.bashrc
$ cat /tmp/b.bashrc
alias answer='echo 42'

$ bash -ix -c exit 2>&1 | grep -E 'source | \. |alias '
+ alias 'ls=ls --color=auto'
+ source /tmp/a.bashrc
++ . /tmp/b.bashrc
+++ alias 'answer=echo 42'
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

Along the lines of Stéphane's similar answer, here's a way to run an interactive bash shell in trace mode (running the single command exit), piped to a grep that shows only the source and alias commands; the source command immediately above the alias of interest should be the file that contains the alias command.

bash -ix -c exit 2>&1 |grep -E 'source |alias '

An instrumented run:

$ tail -1 ~/.bashrc
[ -f /tmp/a.bashrc ] && source /tmp/a.bashrc
$ cat /tmp/a.bashrc
[ -f /tmp/b.bashrc ] && source /tmp/b.bashrc
$ cat /tmp/b.bashrc
alias answer='echo 42'

$ bash -ix -c exit 2>&1 |grep -E 'source |alias '
+ alias 'ls=ls --color=auto'
+ source /tmp/a.bashrc
++ source /tmp/b.bashrc
+++ alias 'answer=echo 42'