check isatty in bash

后端 未结 4 531
予麋鹿
予麋鹿 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:22

    to elaborate, I would try

     if [ -t 0 ] ; then
        # this shell has a std-input, so we're not in batch mode 
       .....
     else
        # we're in batch mode
    
        ....
     fi
    

    I hope this helps.

提交回复
热议问题