Afficher un message
Vieux 07/03/2006, 08h55   #4
Pascal Bourguignon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Détecter si un script est exécuté en intéractif ou en batch

Chris <chris@sra.fr> writes:

> Marbolito a écrit :
>> Bonjour
>> Existe t-il une commande Unix permettant de savoir si le script en
>> cours d'exécution est executé en batch ou en intéractif ?
>> J'aimerais la chose suivante : dès le moment où un script est
>> exécuté manuellement il faut alors qu'il soit remplacé par un batch.
>> Je sais qu'il existe le & pour le soumettre directement : c'est juste
>> une convivialité supplémentaire afin d'éviter que plusieurs
>> personnes soumettent en même temps un script merci
>>

>
> Extrait de /etc/bash.bashrc d'une Debian Sarge
>
> # If running interactively, then:
> if [ "$PS1" ]; then


As always, first: man bash

An interactive shell is one started without non-option arguments
and without the -c option whose standard input and error are both
connected to terminals (as determined by isatty(3)), or one
started with the -i option. PS1 is set and $- includes i if bash
is interactive, allowing a shell script or a startup file to test
this state.

I would rather test $- for i, because any careless initialization file
could set PS1 even for non-interactive shells.

case "$-" in
*i*) echo "interactif" ;;
*) echo "batch" ;;
esac

--
__Pascal Bourguignon__ http://www.informatimago.com/

ATTENTION: Despite any other listing of product contents found
herein, the consumer is advised that, in actuality, this product
consists of 99.9999999999% empty space.
  Réponse avec citation
 
Page generated in 0,06021 seconds with 9 queries