[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Root access in subshell
From: |
Bob Proulx |
Subject: |
Re: [Help-bash] Root access in subshell |
Date: |
Mon, 3 Feb 2014 17:18:46 -0700 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Richard Taubo wrote:
> Bob Proulx wrote:
> > That works just fine to "return feedback to the calling shell". What
> > more do you want?
>
> I was trying to make a distinction between how the Find command run
> in the main shell would show the result directly in the terminal,
> whereas the result of a Find command in a subshell would have to be
> set to a variable before the main shell could display the result in
> the terminal.
>
> Am I clearer, or is that just as bad?
Better. :-) The issue was "feedback". In the above I now know you
mean output from the program. At least postulated it might be the
exit code. (Which is also returned.)
> in the main shell would show the result directly in the terminal,
> whereas the result of a Find command in a subshell would have to be
> set to a variable before the main shell could display the result in
> the terminal.
If you want the output to go to the terminal (instead of back to the
main shell) then instead of $(...) you want (...). The $(...) runs a
subshell and takes the stdout and replaces it on the command line. As
you say it does not show up to the terminal. Instead it is handed
back to the calling shell for handling.
If you use (...) instead then it will invoke a subshell. The output
is not redirected. The output will go to the same place it would have
gone without the subshell. In that case though the main shell does
not receive it as it is printed to the standard output aka the
terminal.
output=$(find / -user myuser)
Versus this:
(find / -user myuser)
Both run in a subshell. In the latter the output goes to the
terminal.
However in the latter while there is no need for the subshell. It
might as well just be this:
find / -user myuser
Bob
- Re: [Help-bash] Root access in subshell, (continued)
Re: [Help-bash] Root access in subshell, Chris Down, 2014/02/03
Re: [Help-bash] Root access in subshell, Seth David Schoen, 2014/02/03
Re: [Help-bash] Root access in subshell, Richard Taubo, 2014/02/04