garabik/grc

GNU make: grc causes shell builtin `read -p "prompt text: "` to not print to terminal in Makefile

trinitronx opened this issue · 3 comments

When using the read -r -p "some prompt here: " bash builtin and having grc loaded into the shell, it appears that the prompt is never displayed. This can cause confusion with things that spawn sub-shells such as make, and probably some bash scripts (maybe other tools too).

Here is a Makefile to reproduce the issue

To reproduce:

  1. Install & load grc into ~/.bashrc
  • For example: brew install grc , then add the following to ~/.bashrc: source "$(brew --prefix)/etc/grc.bashrc"
  1. Spawn a bash shell & cd to the directory with this Makefile
  2. Run make test
  3. Watch as you are not prompted by read (as the Makefile is written to do)
  4. Press enter and see that read was actually expecting input, which you were unaware of
  5. Try again, this time typing something and hitting enter... now it shows you it did read some input and set a variable.

Then, try commenting out the source line which loads grc into the shell. Retry the same make test and see the prompt is shown.

I'm stumped as to why loading grc is affecting shell builtins in this way... the entire contents of the file under $(brew --prefix)/etc/grc.bashrc only has alias definitions:

GRC=`which grc`
if [ "$TERM" != dumb ] && [ -n "$GRC" ]
then
    alias colourify="$GRC -es --colour=auto"
    alias configure='colourify ./configure'
    alias diff='colourify diff'
    alias make='colourify make'
    alias gcc='colourify gcc'
    alias g++='colourify g++'
    alias as='colourify as'
    alias gas='colourify gas'
    alias ld='colourify ld'
    alias netstat='colourify netstat'
    alias ping='colourify ping'
    alias traceroute='colourify /usr/sbin/traceroute'
    alias head='colourify head'
    alias tail='colourify tail'
    alias dig='colourify dig'
    alias mount='colourify mount'
    alias ps='colourify ps'
    alias mtr='colourify mtr'
    alias df='colourify df'
fi

I've tested this with:

bash --version = GNU bash, version 4.4.12(1)-release (x86_64-apple-darwin15.6.0)
make --version = GNU Make 3.81
grc --version = Generic Colouriser 1.11.1 (from Homebrew)

And it also appears to affect the default shell /bin/sh on mac as well:

/bin/sh
sh-3.2$ source "`brew --prefix`/etc/grc.bashrc"
sh-3.2$ make test

You must specify SOME_ENV_VAR or set env variable SOME_ENV_VAR !
Enter SOME_ENV_VAR (eg 'bar') (set environment variable SOME_ENV_VAR to skip this prompt): make: *** [test] Error 1

/bin/sh --version = GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
make --version = GNU Make 3.81
grc --version = Generic Colouriser 1.11.1 (from Homebrew)

Ah, I see why it's being used in this case... it's this: alias make='colourify make'

FYI: I have validated that this behavior has something to do with the -es flags defined in the alias colourify="$GRC -es --colour=auto"

Editing the grc.bashrc file and taking these out for the make alias seems to fix the output from read:

vi $(brew --prefix)/etc/grc.bashrc:

Edits made:

GRC="$(which grc)"
if [ "$TERM" != dumb ] && [ -n "$GRC" ]; then
    alias colourify="$GRC -es --colour=auto"
# [...SNIP...]
# BEGIN EDIT
#    alias make='colourify make'
    alias colorspecial='$GRC --colour=auto'
    alias make='colorspecial make'
# END EDIT
# [...SNIP...]