I would like to set -x temporarily in my script and then return in to the original state.
Is there a way to do it without starting new subshell?
Something like
echo_was_on=.......
... ...
if $echo_was_on; then set -x; else set +x; fi
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can check the value of
$-to see the current options; if it contains an x, it was set. You can check like so:In case it’s not familiar to you: the
${}above is a Bash Substring Replacement, which takes the variable-and replaces anything that’s not anxwith nothing, leaving just thexbehind (or nothing, if there was no x)