|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 ? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 ? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 ? |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 ? |
|
![]() |
| Outils de la discussion | |
|
|