help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Is there a way to make unamed pipe nonexist upon error?


From: Peng Yu
Subject: Re: [Help-bash] Is there a way to make unamed pipe nonexist upon error?
Date: Thu, 26 Sep 2019 12:01:28 -0500

> pipes have nothing to do with terminals, they are a
> communication device between two processes. The data you send at
> one end is read at the other end. Some reader process could want
> to treat some sequence of byte as special. That's what we do
> here with the "FAILED" sequence which we treat as meaning
> failure.
>
> pseudo-terminal devices are another form of communication
> device, which can be used for instance for a process to interact
> with a terminal emulator application. The terminal emulator
> translates what it reads from the reading end of that
> pseudo-pipe to things to display on its emulated screen. It
> interprets some byte sequence specially (like "\e[1m" to enable
> a bold attribute).

What I mean is that iTerm2 use the escape sequences to do special
things. However, if the data (say the binary data from an image file)
actually contains the sequences as well, it will fail. But since
iTerm2 can use these escape sequences, it can be fairly safe to assume
such escape sequences will not occur in real data.

The bottom line is if there are sequences that never appear in real
data, then they can be used to communicate in unnamed.

Now, the question is what sequences can be assumed never (or almost
never) appear in real data.

> I did say "On Linux" above. That will only work on Linux AFAIK.
> That feature was added in 4.89 in 2015

I'd like to try your code. Are you able to make it work on Mac OS X.

> FWIW, awk will interpret that command line using /bin/sh and on
> macOS, /bin/sh happens to be bash, and bash happens to be able
> to export functions via the environment.

Even /bin/sh is frequently the same as /bin/bash, they are not always
the case. This can cause cross-platform issues. Also I remember that
bash will test the file name. So even /bin/sh is just a symlink to
/bin/bash or is a copy of /bin/bash, I think /bin/sh and /bin/bash
will behave differently in some way?

Last, I have a library of bash scripts. It is not a good way to envoke
them in awk as that means every time I use awk, I have reload those
scripts.

So the first way of communicating with escape sequences seems still to
be the best way as long as there are escape sequences that don't
appear in real data.

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]