0

I use strace to trace the behavior of a bash process. The purpose is to find out the order bash loads its configuration files.

I am running the following command under zsh:

strace -e openat bash

After running this command, I end up in a new bash shell, but I don't want that to happen. Is there any way to trace the bash command without actually starting new bash interactive shell?

I searched online but couldn't find anything. I was trying this with exec: strace -e openat "$(exec bash)" 2>&1, but still my shell changes to bash from zsh.

5
  • You are starting a bash shell, so naturally, you will be left inside an interactive bash session (note: you do not log in again, only starting another shell session). If you want to exit that shell session, can't you just type exit? Commented Jan 23, 2024 at 11:51
  • Yes, I can use Ctrl+d as well instead of exit but was curious if there is a way to trace without leaving zsh itself. Commented Jan 23, 2024 at 11:54
  • 2
    Well, you could stace bash running a non-interactive shell with strace bash -c 'exit' or similar, but since you want to investigate how that shell reads its startup files, you'd get a different result as what files are being read by default are different depending on if the shell is started as an interactive, non-interactive or login shell. This does sound a bit like an X-Y question. What is it you are trying to figure out by doing this? It strikes me that the order in which the shell reads its startup files is documented in the manual. Commented Jan 23, 2024 at 11:58
  • 1
    Also note that unless you explicitly replace the zsh process with exec, you are not "leaving" zsh. You are only starting another application (bash) and you return to your zsh shell when the application has terminated. Commented Jan 23, 2024 at 12:00
  • Considering the startup files, also remember that Bash reads a different set of startup files when started as a login shell vs. a non-login shell. But yes, it's documented in the manual, even though the actual rules are somewhat confusing. Commented Jan 23, 2024 at 12:04

1 Answer 1

3

You can ask bash to exit immediately, and force it to behave like an interactive and/or login shell:

strace -e openat bash -i -c exit

Add -l to make bash act like an interactive login shell.

Note that this will also show files read when exiting (.bash_logout etc.).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.