[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using terminal output as input



In <[🔎] 880dece00905140755w67aefd85uacffa635c30656b@mail.gmail.com>, Dotan Cohen 
wrote:
>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.

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.

These are particularly useful when combined with the "UNIX filter commands" 
tr, grep, sed, cut, paste, and awk plus the tee command.
-- 
Boyd Stephen Smith Jr.           	 ,= ,-_-. =.
bss@iguanasuicide.net            	((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy 	 `-'(. .)`-'
http://iguanasuicide.net/        	     \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: