Is there an equivalent of POSIX shells' set -x or set -o xtrace that cause the shell to display the commands being run in the fish shell?

2 Answers 2


Since fish 3.1.0, the fish_trace variable makes this functionality available:

> set fish_trace on; isatty; set -e fish_trace
++ source share/fish/functions/isatty.fish
++++ function isatty -d 'Tests if a file descriptor is a tty'
+ isatty
+++ set -l options h/help
+++ argparse -n isatty h/help --
+++ if
+++ set -q _flag_help
+++ end if
+++ if
+++ set -q 'argv[2]'
+++ end if
+++ set -l fd
++++ set fd 0
+++ '[' -t 0 ']'
+ set -e fish_trace

The location of the trace output is controlled by the --debug-output option to the fish process.

Before fish 3.1.0, you can use fish -p some_trace_file to run a fish session which outputs a profile to "some_trace_file", which can achieve almost the same effect (with some disadvantages - see the comments below).

  • 1
    Thanks. That's useful indeed. The output is more readily usable than with -d4, and it gives that useful timing information and function call depth. One has to wait until the shell exits (and not die of a signal) though to get any of that output. Nov 17, 2015 at 15:23

The closest thing I can see, similar to set -o xtrace in zsh, by calling fish with -d 4 or --debug-level=4:

$ fish -d 4 -c 'echo 1'
fish: Exec job 'builtin source /usr/share/fish/config.fish 2>/dev/null' with id 1
fish: Exec job 'set -g IFS \n\ \t' with id 2
fish: Set status of set -g IFS \n\ \t to 0 using short circuit
fish: Job is constructed
fish: Continue job 2, gid 0 (set -g IFS \n\ \t), COMPLETED, NON-INTERACTIVE
fish: Exec job 'echo 1' with id 1
fish: Set status of echo 1 to 0 using short circuit
fish: Job is constructed
fish: Continue job 1, gid 0 (echo 1), COMPLETED, NON-INTERACTIVE
  • Thanks. Those Set status of are only output for builtins though. You get more interesting output with -d4 (and piping to grep '^fish: Exec job' for instance) Nov 17, 2015 at 15:19
  • @StéphaneChazelas: yeah, of course, -d4 make it more similar to xtrace.
    – cuonglm
    Nov 17, 2015 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.