help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Anyone clarify ?


From: Tapani Tarvainen
Subject: Re: Anyone clarify ?
Date: Wed, 10 May 2023 14:33:42 +0300

On Wed, May 10, 2023 at 07:09:28AM -0400, Greg Wooledge (greg@wooledge.org) 
wrote:
> > May 9, 2023 at 23:20 by budikusasi_at_gmail.com_63l618u2@duck.com:
> > > Anyone clarify what the definitive difference between:
> > >
> > >  3<&0
> > >
> > >  exec 3<&0
> 
> unicorn:~$ help exec
> exec: exec [-cl] [-a name] [command [argument ...]] [redirection ...]
>     Replace the shell with the given command.
>     
>     Execute COMMAND, replacing this shell with the specified program.
>     ARGUMENTS become the arguments to COMMAND.  If COMMAND is not specified,
>     any redirections take effect in the current shell.
> 
>     [...]
> 
> So: the first one is just a redirection, and would normally need to be
> part of a larger command.

Well yes, but if the question was how it works as is, the answer
is that it does nothing: the redirection is done for the empty
command line, or implied null command, and then forgotten.
With exec it does the redirection for the current shell so
it stays in effect until explicitly undone.

This is easier to demonstrate with output:

$ 3>&1
$ echo x >&3
bash: 3: Bad file descriptor
$ exec 3>&1
$ echo x >&3
x

The first 3>&1 on the line by itself didn't affect subsequent
command, whereas the one with exec did.

-- 
Tapani Tarvainen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]