Celeb Glow
general | February 27, 2026

Print all commands in a bash function

I am trying to debug a bash function.

Is it possible to print all the commands executed by a bash function? I know that it is possible to print all the commands by a bash script by changing

#!/bin/bash

to

#!/bin/bash -x

How do I get the same effect for a bash function?

Thank you.

1 Answer

You need to edit the function to add and remove tracing, eg:-

FuncName()
{ set -x ;# Enable tracing on entry ... (function code) ... set +x ;# Disable tracing on exit
}
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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