On 28.02.2024 00:10, Lawrence D'Oliveiro wrote:
On Tue, 27 Feb 2024 13:18:20 +0100, Janis Papanagnou wrote:
On 26.02.2024 21:31, Lawrence D'Oliveiro wrote:
Question: How would you do two separate <<-strings in the same shell
command?
Can you give an example what you intend here? (With what semantics?)
Since '<<' is redirecting the here-document text to stdin of the command >>> you can have only one channel.
Perl lets you do something like
func(<<EOD1, <<EOD2);
... contents of first string ...
EOD1
... contents of second string ...
EOD2
But this doesn’t work in Bash. However, in a Posix shell, remember you can >> specify the number of the file descriptor you want to redirect, e.g.
diff -u /dev/fd/8 /dev/fd/9 8<<'EOD1' 9<<'EOD2'
... contents of first string ...
EOD1
... contents of second string ...
EOD2
Note I add the single quotes to prevent expansion of “$”-sequences within
the strings. (I think this might be needed in Perl, too.)
I see. - Yes, you can do that in POSIX shells as well. [...]
You found a syntactic solution already, but that requires some
non-standard /dev/fd OS support. Newer shells allow also process
substitution diff <(...) <(...) to support pipes where files
are expected, but that also relies on the existence of /dev/fd,
AFAICT.
On 2024-02-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
You found a syntactic solution already, but that requires some
non-standard /dev/fd OS support. Newer shells allow also process
substitution diff <(...) <(...) to support pipes where files
are expected, but that also relies on the existence of /dev/fd,
AFAICT.
Bash, at least, can alternatively use named pipes.
This is on FreeBSD:
bash$ cat s
#!/bin/sh
echo "$@"
ls -l "$@"
bash$ ./s <(echo hello)
/tmp//sh-np.Uawtgm
prw------- 1 naddy wheel 0 Feb 28 16:19 /tmp//sh-np.Uawtgm
it would be interesting to see some neat solution that does notQuestion: How would you do two separate <<-strings in the same
shell command?
Bash, at least, can alternatively use named pipes.
Yes, below you're using newer shells' process substitution (as I
also did above). It implicitly requires an OS supporting /dev/fd .
bash$ ./s <(echo hello)
/tmp//sh-np.Uawtgm
prw------- 1 naddy wheel 0 Feb 28 16:19 /tmp//sh-np.Uawtgm
On 2024-02-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Yes, below you're using newer shells' process substitution (as I
also did above). It implicitly requires an OS supporting /dev/fd .
It does not! That was my point. Bash implements process substitution
with temporary named pipes on systems where /dev/fd/* may not be
available:
The Bolsky/Korn Kornshell book says that Kornshell supports process substitution on Unix systems that support /dev/fd/ and I'd have
expected that Bash adopted that from Kornshell (as it did with so
many Kornshell features). But probably not...
Or does Kornshell also support it independently of /dev/fd/ also
with named pipes? (I cannot check that on my system.)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 11:33:28 |
Calls: | 9,783 |
Calls today: | 2 |
Files: | 13,748 |
Messages: | 6,187,342 |