Command: bash -c "some_command_line" versus ONLY some_command_line
I have not found an explanation of
the need to use command like so: Code:
bash -c "your_command_line" Code:
your_command_line Below is the first time I see why using prefix "bash -c" in a command line is needed. Code:
user@host /proc/sys/kernel $ cat /proc/sys/kernel/threads-max and why it is needed. Thank you. |
Clearly explained in
Code:
man bash |
@Habitual
Thank you for your great habits of using man pages, and bringing awareness of the great man pages every chance you got. Great. There is no need for www.linuxquestions.org since man pages very clearly explain everything. Time to shut down www.linuxquestions.org. Agree? Yes? No? |
That happens because the output redirection is handled by the shell within which you are executing the command, not by the command being issued.
So if root owns the target of the redirect... Code:
-rw-r--r-- 1 root root 0 Jun 13 16:54 rfile But like this... Code:
sudo bash -c "echo 'some text' >rfile" |
Quote:
Actually, if more users like yourself had learned to search the existing documentation, there would be nothing for me to do. So help me break the habit and read some. End Transmission. |
@astrogeek:
Thank you. That sounds logical. I understand your explanation like so: (this is redundant, for newbie clarification and reference only) There are 2 commands (processes) running in command : Quote:
it is given sudo privileges ( sudo not really needed here). Then when it completes and returns to Bash shell, the first operation result is to be redirected as part of the second command (to be executed from and BY the Bash shell). However, the Bash shell does not have sudo privileges. that is why access to /proc/sys/kernel/thread-max was denied. So in order to run these sequential commands (some of which may need sudo privileges down the commands chain) we need to run them in a shell with elevated privileges. Hence the need to launch privilege Bash shell like so: Quote:
|
Quote:
Quote:
|
All times are GMT -5. The time now is 09:42 PM. |