[devel] Re: I: console-tools-0.2.3-ipl14.1mdk

Ivan Zakharyaschev =?iso-8859-1?q?imz_=CE=C1_altlinux=2Eru?=
Вт Ноя 5 19:39:36 MSK 2002


	Hello!

On Tue, 5 Nov 2002, Dmitry V. Levin wrote:

> > А чем твоя проверка на интерактивность лучше PS1 (PS1 я нашёл в
> info
> > bash и успокоился, уверенный в том, что это корректно).
>
> Такая же проверка есть в /etc/bashrc.

Я ещё раз заглянул на ту же страницу -- там написаны оба варианта, так
что, наверное, больщой разницы нет. $- немного понятнее.

В скрипте Mandrake есть ещё такая проверка:

# bash sets the $- variable, and puts 'c' in it if it is a
non-interactive
# shell
# For other shells, I assume $- is not available
if [ "$SHELL" = "/bin/bash" ]; then
		if echo $- | grep 'c' >/dev/null; then
				return  #non-interactive
		fi
fi

Есть ли какие-нибудь соображения, нужна ли она в дополнение к уже
имеющейся? i и c друг друга не исключают:

$ sh -ic 'echo $-'
himBc


А вот отрывок из bash.info, про который я говорил:

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:

     case "$-" in
     *i*)	echo This shell is interactive ;;
     *)	echo This shell is not interactive ;;
     esac

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

     if [ -z "$PS1" ]; then
             echo This shell is not interactive
     else
             echo This shell is interactive
     fi




-- 
С наилучшими пожеланиями,
Иван Захарьящев, Москва




Подробная информация о списке рассылки Devel