[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Weird set -u error



On Fri, 26 Aug 2022, tomas@tuxteam.de wrote:

On Fri, Aug 26, 2022 at 08:17:10AM +0100, Tim Woodall wrote:
$ cat Makefile.test
SHELL := /bin/bash -u
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:

all:
        echo done
$ make -f Makefile.test
echo done
done
$ make -f Makefile.test | cat
echo done
/etc/bash.bashrc: line 7: PS1: unbound variable
                   ^^^^^^^^^^^

[...]

Why do I get that unbound variable error? (I know how to fix it, I just
don't understand why it only happens when I pipe the output)

If I were you, I'd  go looking at your /etc/bashrc and see what's around
line 7. Mine says (line numbers added by me):

Yes, I know how to fix it. That is straight forward. SUDO_USER and
SUDO_PS1 have similar issues, debian_chroot works in the presence of set
-u

But I don't understand why /etc/bash.bashrc is being sourced by make
when piping make through cat. Make is doing something like:

source /etc/bash.bashrc; bash -c 'echo done' - but only when the output
is to a pipe.

bash -uc 'echo done'
doesn't have the problem whether or not it is outputting to a pipe.

Tim


Reply to: