#!/bin/bash -x
echo This is a script that has debugging turned on
This script outputs
+ echo This is a script that has debugging turned on
This is a script that has debugging turned on
I want to get rid of these +'s by deleting them or replacing them. I expected sed could fix my problem (sed 's/^\++//g'
) -- But this approach doesn't affect the debug output lines.
With some more experimenting, I discovered that the debug output seems to be getting written to stderr (inferred this with the command ./test.sh 2>/dev/null
which the output then excludes the debug lines)
With this new information, I would expect this to work
./test.sh 2>&1 | sed 's/^\++//g'
But, alas, I still get the same undesired output:
+ echo This is a script that has debugging turned on
This is a script that has debugging turned on
-x
has added? Why not just remove the-x
? – Jeff Schaller Oct 23 '18 at 17:58/bin/bash
in your shebang line! Always defer toenv
:#!/usr/bin/env bash
. Unfortunately this approach no longer allows you to pass additional parameters (i.e.-x
in this case). – Konrad Rudolph Oct 23 '18 at 22:49foo 2>&1 | bar
can be written more compactly asfoo |& bar
– Andrea Corbellini Oct 23 '18 at 23:33