I have some lengthy scripts calling each other and I want their output to be more descriptive. The idea is to customize the echo command for each script with something like below.
My question is, how to make it non recursive, using echo?
this is script1.sh
#!/bin/bash
#Original version:
#function echo(){ echo $(basename $0 .sh): $1; }
#Version after fixes
function echo(){ builtin echo -n "$(basename $0 .sh): ">&2; builtin echo $@ ; }
echo Info
./script2.sh
this is script2.sh
#!/bin/bash
#Original version:
#function echo(){ echo $(basename $0 .sh): $1; }
#Version after fixes
function echo(){ builtin echo -n "$(basename $0 .sh): ">&2; builtin echo $@ ; }
echo Info
exit 0
so the output should be:
>./script1.sh
script1: Info
script2: Info
— EDIT
Bonus:
>./script1.sh 2> /dev/null
Info
Info
use the
builtinkeyword:here the help page: