Bash Reference Mamual

2020-10-17 Thread Craig H Maynard
Hi,

In section 3.5.4 "Command Substitution", the following sentence may have a typo:

> The command substitution $(cat file) can be replaced by the equivalent but 
> faster $(< file).


My proposed change:

> The command substitution $(cat file) can be replaced by the equivalent but 
> faster <(cat file).


If the manual is correct and I misunderstood something, please let me know.

Thanks,
Craig

--
Craig H Maynard
103 North Road
Wakefield, RI 02879
(401) 413-2376




Re: Bash Reference Mamual

2020-10-17 Thread Eduardo Bustamante
On Sat, Oct 17, 2020 at 3:48 PM Craig H Maynard  wrote:

> Hi,
>
> In section 3.5.4 "Command Substitution", the following sentence may have a
> typo:
>
> > The command substitution $(cat file) can be replaced by the equivalent
> but faster $(< file).
>
>
> My proposed change:
>
> > The command substitution $(cat file) can be replaced by the equivalent
> but faster <(cat file).
>
>
> If the manual is correct and I misunderstood something, please let me know.
>

Hi Craig,

<(cat file) and $(cat file) are not equivalent constructs. The former will
expand to a file name (e.g. "/dev/fd/63"), whereas the latter will expand
to the contents of the file.


In the case of   $(cat file)  and $(< file), they are equivalent, except
that in the second case there's no external command ("cat"), and instead
Bash reads the file and does the expansion itself.


Re: Bash Reference Mamual

2020-10-17 Thread Lawrence Velázquez
> On Oct 17, 2020, at 7:35 PM, Eduardo Bustamante  wrote:
> 
> <(cat file) and $(cat file) are not equivalent constructs. The former will
> expand to a file name (e.g. "/dev/fd/63"), whereas the latter will expand
> to the contents of the file.

If you want terms you can look up, $(cat file) and $(< file) are
*command substitutions*, while <(cat file) is a *process substitution*.

$ printf 'FILE CONTENTS' >tmp
$ printf '|%s|\n' "$(cat tmp)"
|FILE CONTENTS|
$ printf '|%s|\n' "$(< tmp)"
|FILE CONTENTS|
$ printf '|%s|\n' "<(cat tmp)"
|<(cat tmp)|
$ printf '|%s|\n' <(cat tmp)
|/dev/fd/63|


--
vq