-1
cat <(echo yes)

Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15.

Yet on Bash 4.4.20 it throws an error:

sh -c "cat <(echo yes)"
sh: -c: line 0: syntax error near unexpected token `('

Why the error?

Are there any other ways sh -c differs from running sh and then typing the command?

Zaz
  • 2,589
  • 1
    Is sh bash in both cases? If the list of differences is given in https://www.gnu.org/software/bash/manual/bash.html#Bash-POSIX-Mode (which may vary from version to version, check the installed documentation to see for each version). If it's some other shell that's sh, there will be other differences. – muru Jul 07 '23 at 05:16
  • echo yes, echo yes | cat and echo yes | cat /dev/stdin also output yes, can you give a more relevant example of why you'd need to use ksh-style process substitution. – Stéphane Chazelas Jul 07 '23 at 05:50
  • sh is a link to dash in my linucies (is that the plural of linux?) - what is it in yours? – Jaromanda X Jul 07 '23 at 05:57
  • 1
    What do you mean by "regular shell"? sh is generally a POSIX-compliant shell, so you shouldn't expect it to understand the extra features of other shells. It seems you have the world backward, thinking of sh as an exception rather than as the base. – Toby Speight Jul 07 '23 at 06:16

1 Answers1

1

When you run Bash as sh, it starts in POSIX mode, which disables some nonstandard features, including process substitution in versions before Bash 5.1. From the CHANGES file in the distribution:

This document details the changes between this version, bash-5.1-alpha, and
the previous version, bash-5.0-release.
  1. New Features in Bash

u. Process substitution is now available in posix mode.

The fact that it works in the most recent versions is likely the reason it's not listed in the reference manual page on POSIX mode.

Note that on many systems, sh is not Bash at all. If you want Bash, run bash.

ilkkachu
  • 138,973