Re: Using terminal output as input
2009/5/14 Boyd Stephen Smith Jr. <email@example.com>:
> In <firstname.lastname@example.org>, Dotan Cohen
>>I am using a Debian-based distro (Ubuntu). Often I need to use the
>>output of one terminal command as the input for another.
> UNIX-ish OSes and programs are designed for this, but you'll have to learn
> the small tools in order to build the custom tools you want.
> In general, terminal commands read from "standard input" and write to
> "standard output" and "standard error". These names are often shorted:
> standard input = stdin = file descriptor 0 = fd 0
> standard output = stdout = file descriptor 1 = fd 1
> standard error = stderr = file descriptor 2 = fd 2
> By default, all of these are attached to your terminal. However, you can
> use redirection and pipes to have a terminal command read or write to other
> files or other commands.
> "> file" makes a command's standard output write to a new, empty file.
> ">> file" makes a command's standard output append to an existing file.
> "< file" makes a command's standard input read from an existing file.
> "cmd1 | cmd2" makes cmd1's standard output write cmd2's standard input.
> "$(cmd1)" captures a command's standard output (removing the last '\n' if
> there is one) and uses it as part of the shell's input -- similar to a
> variable expansion.
> info:/bash/Redirections and info:/bash/Pipelines has more details.
Thanks. This is pretty much what I knew, but stated better than I understood.
> http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html is
> the canonical reference, but it is dry, technical, and probably has a lot
> more details that you are not interested in immediately. The link also may
> require registration.
No registration needed, but it is a difficult read.
> These are particularly useful when combined with the "UNIX filter commands"
> tr, grep, sed, cut, paste, and awk plus the tee command.
I am baffled that one must type in the output to commands. For
instance, the sysadmin may need to use the existing DHCP IP address
for one reason or another. After running ifconfig, where the address
is stated, why must he type it in? I'm not looking for copy-paste in
the GUI sense, but some sort of this-to-there method for carrying
small bits of data seems so useful, basic, and would help prevent