[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Understanding read -r
From: |
Dan Douglas |
Subject: |
Re: [Help-bash] Understanding read -r |
Date: |
Thu, 04 Oct 2012 19:00:29 -0500 |
User-agent: |
KMail/4.8.3 (Linux/3.4.6-pf+; KDE/4.8.3; x86_64; ; ) |
On Thursday, October 04, 2012 05:25:55 PM Eric Blake wrote:
> On 10/04/2012 05:16 PM, Bob Proulx wrote:
>
> >> { var=$(</dev/stdin); } <<EOF
>
> >
> > I personally dislike the use of /dev/stdin and the others because they
> > are non-portable across kernels and cause me trouble.
>
> Bash special-cases /dev/stdin so that it works even if your kernel
> doesn't support it. Of course, that special casing is only applicable
> to situations where bash is opening the file, and not where you pass the
> string '/dev/stdin/ as an argument to some other program, so I tend to
> agree with your analysis that it gets even harder to use when it works
> in some, but not all, contexts within the same machine.
Oh it applies to builtins opening the file passed as an argument too? I
thought it was only special redirection syntax (like in this case). If that's
true I might use the tee loadable more frequently.
> >> var=<<EOF
> >> ...
> >> EOF
> >>
> >> This is optimized to happen in memory with no temporary file.
> >
> > Looks like a nice feature.
>
> How is it any different from:
> var="...
> "
Just in the handling of escapes and nested quotes. I imagine the quoted
delimiter variant is more useful. Example usecase:
defaultTrap=<<'EOF'
...
EOF
...
trap "${var:-$defaultTrap}" EXIT
...
--
Dan Douglas
signature.asc
Description: This is a digitally signed message part.