How to execute an output string without bash's command substitution?For example, if I type in terminal tshark, and the program isn't installed yet, I will recieve an error message like:_some text_sudo apt-get install tsharkNow I want to execute this last line without copy&paste or transcription.If I try$ tshark 2> >(tail -1)sudo apt-get install tsharkI will get this last line I want to execute.And if I want to execute this string, of course bash's command substitution  works and install everything properly:$ $(tshark 2> >(tail -1))But if I don't use bash's command substitution, and pipe this to xargs like$ tshark 2> >(tail -1) | xargssudo apt-get install tsharkI am wondering why piping to xargs seems to have no effect.But if I try$ tshark 2> >(tail -1) | xargs xargssudo prompt's me correct for password, and than apt-get abbort's after Y/N for installing or not.The same result occurs if I pipe to bash.Any response or hint is welcome.
How to execute an output string without bash's command substitution?
bash;apt;pipe;xargs;process substitution
AnswerYou cannot reuse the output of a command that was not explicitly captured (pipes, etc.) unless you re-execute the command and capture the output yourself.Bash does not store command output in any variables, unlike how it does store command exit codes and command history. Your terminal has the output and bash does not bother keeping a copy for itself as well.So if you want to avoid command substitution all together, I am going to conclude you can't get there from here.OptionsIf the real question is How can I easily grab the output that I see on the line above in the terminal and slap it into the command prompt as a command without a lot of typing? you can tackle this a couple of ways.Use readline shortcuts to make editing a command more painless.For example, your response to @choroba's fine suggestion elsewhere is that editing the last command is too much typing. The readline shortcuts CTRL-a and CTRL-e can make editing the last command (reached with CTRL-p instead of the UP waaaay over to the right) much faster.Use a terminal multiplexer such as screen or tmux. I prefer tumx. Copying and pasting is pretty painless with a simple CTRL-a CTRL-[ to jump into copy mode and a few more VI keys and you have just copied the line you want right into the next prompt (with tmux setup with a CTRL-a leader key.Hope this offers some other perspectives.