diff --git a/dist/libexec/common-shared b/dist/libexec/common-shared index fa1e62c09241..48476c11b63e 100644 --- a/dist/libexec/common-shared +++ b/dist/libexec/common-shared @@ -6,16 +6,22 @@ # * Credits: This script is based on the script generated by sbt-pack. # *--------------------------------------------------------------------------*/ -# save terminal settings -saved_stty=$(stty -g 2>/dev/null) -# clear on error so we don't later try to restore them -if [[ ! $? ]]; then - saved_stty="" +if [ -e /usr/bin/tty -a "`tty`" != "not a tty" -a ! -p /dev/stdin ]; then + isterminal=1 + # save terminal settings + saved_stty=$(stty -g 2>/dev/null) + # clear on error so we don't later try to restore them + if [[ ! $? ]]; then + saved_stty="" + isterminal=0 + fi +else + isterminal=0 fi # restore stty settings (echo in particular) function restoreSttySettings() { - stty $saved_stty + [ $isterminal -eq 1 ] && stty $saved_stty saved_stty="" } @@ -61,7 +67,7 @@ if [[ ${cygwin-} || ${mingw-} || ${msys-} ]]; then CYGPATHCMD=`which cygpath 2>/dev/null` case "$TERM" in rxvt* | xterm* | cygwin*) - stty -icanon min 1 -echo + [ $isterminal -eq 1 ] && stty -icanon min 1 -echo JAVA_OPTS="$JAVA_OPTS -Djline.terminal=unix" ;; esac