Chinaunix首页 | 论坛 | 博客
  • 博客访问: 22661
  • 博文数量: 7
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 68
  • 用 户 组: 普通用户
  • 注册时间: 2014-02-20 12:06
文章分类
文章存档

2014年(7)

我的朋友

分类: LINUX

2014-02-20 16:13:36




6.3.1 What is an Interactive Shell?

An interactive shell is one started without non-option arguments, unless -s is specified, without specifying the -c option, and whose input and error output are both connected to terminals (as determined by isatty(3)), or one started with the -i option.


An interactive shell generally reads from and writes to a user’s terminal.


The -s invocation option may be used to set the positional parameters when an interactive shell is started.


6.3.2 Is this Shell Interactive?

To determine within a startup script whether or not Bash is running interactively, test the value of the ‘-’ special parameter. It contains i when the shell is interactive.  For example:

点击(此处)折叠或打开

  1. case "$-" in
  2. *i*) echo This shell is interactive ;;
  3. *) echo This shell is not interactive ;;
  4. esac

Alternatively, startup scripts may examine the variable PS1; it is unset in non-interactive shells, and set in interactive shells.  Thus:

点击(此处)折叠或打开

  1. if [ -z "$PS1" ]; then
  2.         echo This shell is not interactive
  3. else
  4.         echo This shell is interactive
  5. fi

阅读(961) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~