check isatty in bash

后端 未结 4 528
予麋鹿
予麋鹿 2020-12-16 12:29

I want my shell to detect if human behavior, then show the prompt.

So, assume the file name is test.bash

#!/bin/bash
if [ \"x\" != \"${PS1:-x}\" ] ;t         


        
4条回答
  •  情歌与酒
    2020-12-16 13:03

    You could make use of the /usr/bin/tty program:

    if tty -s
    then
        # ...
    fi
    

    I admit that I'm not sure how portable it is, but it's at least part of GNU coreutils.

提交回复
热议问题