PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > printf '\e'
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

printf '\e'

Réponse
 
LinkBack Outils de la discussion
Vieux 25/03/2008, 12h39   #1
Spiros Bousbouras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut printf '\e'

I noticed that the BASH and Korn printf
built-ins output ESC with printf '\e' but
the DAsh printf outputs the actual characters.

With printf '%b' '\e' BASH outputs ESC, while
Korn and DAsh output the characters.

I had a look into POSIX. I'm not sure I've
managed to locate all the relevant sections
but those I've read do not mention \e as an
escape sequence which means that using it is
unspecified behaviour. If I'm right then
which are the allowed behaviours ?
  Réponse avec citation
Vieux 25/03/2008, 12h47   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

Spiros Bousbouras wrote:
> I noticed that the BASH and Korn printf
> built-ins output ESC with printf '\e' but
> the DAsh printf outputs the actual characters.
>
> With printf '%b' '\e' BASH outputs ESC, while
> Korn and DAsh output the characters.


Kornshell's printf man page says \E is ESC.

Janis

>
> I had a look into POSIX. I'm not sure I've
> managed to locate all the relevant sections
> but those I've read do not mention \e as an
> escape sequence which means that using it is
> unspecified behaviour. If I'm right then
> which are the allowed behaviours ?

  Réponse avec citation
Vieux 25/03/2008, 14h49   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

2008-03-25, 04:39(-07), Spiros Bousbouras:
> I noticed that the BASH and Korn printf
> built-ins output ESC with printf '\e' but
> the DAsh printf outputs the actual characters.
>
> With printf '%b' '\e' BASH outputs ESC, while
> Korn and DAsh output the characters.
>
> I had a look into POSIX. I'm not sure I've
> managed to locate all the relevant sections
> but those I've read do not mention \e as an
> escape sequence which means that using it is
> unspecified behaviour. If I'm right then
> which are the allowed behaviours ?


Only '\a', '\b', '\f', '\n', '\r', '\t', '\v' are standard.

printf '\33'
printf '\033'

printf %b '\033'
printf %b '\0033'

are also OK.

printf %b '\33'
is unspecified I think.

printf '\0033' | cat -v
is meant to output '^C3'

but YMMV.

--
Stéphane
  Réponse avec citation
Vieux 25/03/2008, 14h53   #4
Spiros Bousbouras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

On 25 Mar, 13:49, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2008-03-25, 04:39(-07), Spiros Bousbouras:
>
> > I noticed that the BASH and Korn printf
> > built-ins output ESC with printf '\e' but
> > the DAsh printf outputs the actual characters.

>
> > With printf '%b' '\e' BASH outputs ESC, while
> > Korn and DAsh output the characters.

>
> > I had a look into POSIX. I'm not sure I've
> > managed to locate all the relevant sections
> > but those I've read do not mention \e as an
> > escape sequence which means that using it is
> > unspecified behaviour. If I'm right then
> > which are the allowed behaviours ?

>
> Only '\a', '\b', '\f', '\n', '\r', '\t', '\v' are standard.


That's what I thought but can an implementation
output anything it wants with \e or is there a collection
of permitted behaviours ?
  Réponse avec citation
Vieux 25/03/2008, 15h03   #5
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

2008-03-25, 06:53(-07), Spiros Bousbouras:
[...]
>> Only '\a', '\b', '\f', '\n', '\r', '\t', '\v' are standard.

>
> That's what I thought but can an implementation
> output anything it wants with \e or is there a collection
> of permitted behaviours ?


\e is unspecified. If you want to output \e as opposed to the
ESC character, use printf '\\e' or printf %s '\e'

--
Stéphane
  Réponse avec citation
Vieux 25/03/2008, 15h07   #6
Spiros Bousbouras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

On 25 Mar, 14:03, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2008-03-25, 06:53(-07), Spiros Bousbouras:
> [...]
>
> >> Only '\a', '\b', '\f', '\n', '\r', '\t', '\v' are standard.

>
> > That's what I thought but can an implementation
> > output anything it wants with \e or is there a collection
> > of permitted behaviours ?

>
> \e is unspecified. If you want to output \e as opposed to the
> ESC character, use printf '\\e' or printf %s '\e'


What does unspecified mean in POSIX ? In the C standard
it means that the standard specifies a list of behaviours
and the implementation can choose any one of them without
needing to document it.
  Réponse avec citation
Vieux 25/03/2008, 15h19   #7
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

2008-03-25, 07:07(-07), Spiros Bousbouras:
> On 25 Mar, 14:03, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
>> 2008-03-25, 06:53(-07), Spiros Bousbouras:
>> [...]
>>
>> >> Only '\a', '\b', '\f', '\n', '\r', '\t', '\v' are standard.

>>
>> > That's what I thought but can an implementation
>> > output anything it wants with \e or is there a collection
>> > of permitted behaviours ?

>>
>> \e is unspecified. If you want to output \e as opposed to the
>> ESC character, use printf '\\e' or printf %s '\e'

>
> What does unspecified mean in POSIX ? In the C standard
> it means that the standard specifies a list of behaviours
> and the implementation can choose any one of them without
> needing to document it.


That means that if your shell script has:

printf '\e'

you don't know what you'll get, that can be anything, so you
should not use it in a POSIX script that intents to be portable.

And if you're implementing a new "printf" utility, you can do
whatever you want in that case as POSIX doesn't specify the
behavior. So you can issue an error message, you can launch a
web browser, shutdown the machine, output an ESC character,
output an ASCII EOT, ETB, ETX... character, output \e, turn on
terminal echo, erase a character...

--
Stéphane
  Réponse avec citation
Vieux 27/03/2008, 13h18   #8
Spiros Bousbouras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printf '\e'

On 25 Mar, 07:19, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2008-03-25, 07:07(-07), Spiros Bousbouras:
>
> > On 25 Mar, 14:03, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> >> 2008-03-25, 06:53(-07), Spiros Bousbouras:
> >> [...]

>
> >> >> Only '\a', '\b', '\f', '\n', '\r', '\t', '\v' are standard.

>
> >> > That's what I thought but can an implementation
> >> > output anything it wants with \e or is there a collection
> >> > of permitted behaviours ?

>
> >> \e is unspecified. If you want to output \e as opposed to the
> >> ESC character, use printf '\\e' or printf %s '\e'

>
> > What does unspecified mean in POSIX ? In the C standard
> > it means that the standard specifies a list of behaviours
> > and the implementation can choose any one of them without
> > needing to document it.

>
> That means that if your shell script has:
>
> printf '\e'
>
> you don't know what you'll get, that can be anything, so you
> should not use it in a POSIX script that intents to be portable.
>
> And if you're implementing a new "printf" utility, you can do
> whatever you want in that case as POSIX doesn't specify the
> behavior. So you can issue an error message, you can launch a
> web browser, shutdown the machine, output an ESC character,
> output an ASCII EOT, ETB, ETX... character, output \e, turn on
> terminal echo, erase a character...


If that's what unspecified means then what's the difference between
undefined behaviour and unspecified behaviour according to POSIX ?
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h16.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,84525 seconds with 16 queries