[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The 'source x' command doesn't keep variables set by x when source o
From: |
Robert Elz |
Subject: |
Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command |
Date: |
Thu, 14 Nov 2024 09:45:51 +0700 |
Date: Thu, 14 Nov 2024 00:30:32 +0100
From: "#!microsuxx" <fxmbsw7@gmail.com>
Message-ID:
<CAALKErErEf+_ZgiT6+n7HbGNRAi0q-xto2F5RFNTTuq6CJ9iNA@mail.gmail.com>
| i just dunno the exec cmd to bring back the fd 1 and 2 after usage back to
| tty , or restore from saved
Assuming that this is even slightly relevant to the question here (whether
any of this is really necessary), that you accomplish by a sequence like:
exec 7<&0 8>&1 9>&2
exec 0<... 1>... 2>... # (whatever needs to be done)
# commands to use the modified
# stdin, stdout, stderr, (or some subset)
# go here
exec <&7 >&8 2>&9 7<&- 8>&- 9>&- # to restore things to as they
were.
You can use anything you like instead of 7, 8 & 9, they just need to be
unused file descriptors that the shell you're using will allow you to
access - all shells allow fd's 0..9 to be used by scripts (but 0, 1 & 2 are
already in use), some allow lots more than that. You don't need to save
or restore anything you don't need to modify, obviously (ie: don't bother
saving stdin and then not assigning it elsewhere, and if you don't save
it don't attempt to restore it later).
kre
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, (continued)
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Greg Wooledge, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Martin D Kealey, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Yuri, 2024/11/14
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Chet Ramey, 2024/11/14
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Robert Elz, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Yuri, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command,
Robert Elz <=
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Chet Ramey, 2024/11/14
Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Chet Ramey, 2024/11/14