[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Why can redirection be combined in an assignment statement?
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: Why can redirection be combined in an assignment statement? |
Date: |
Mon, 10 May 2021 20:33:39 +0200 |
On Mon, May 10, 2021 at 11:16:59AM -0500, Peng Yu wrote:
> > $ reverse=false; if "$reverse"; then a=$(rev); else a=$(cat); fi
> > <<<"hello"; echo "$a"
> > hello
> > $ reverse=true; if "$reverse"; then a=$(rev); else a=$(cat); fi
> > <<<"hello"; echo "$a"
> > olleh
>
> I am talking about combining just assignment and redirection, which
> comes from these rules.
>
> simple_command_element: WORD
> | ASSIGNMENT_WORD
> | redirection
> ;
>
> simple_command: simple_command_element
> | simple_command simple_command_element
> ;
>
> Your example is not about this case. Therefore, it does not serve the
> purpose of justifying combining assignment and redirection.
Hm... I think that
a=$(cat) <<<"hello"
is exactly this. You may replace <<<"hello" by <somefile if you wish.
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
.
Re: Why can redirection be combined in an assignment statement?, Koichi Murase, 2021/05/10
Re: Why can redirection be combined in an assignment statement?, Eli Schwartz, 2021/05/10
Re: Why can redirection be combined in an assignment statement?, Chet Ramey, 2021/05/10