Entrada YSalida
Entradas y salidas en Bash
Section titled “Entradas y salidas en Bash”Redirigir stdin/stdout/stderr, encadenar con pipes y duplicar salida con tee.
Descriptores
Section titled “Descriptores”| Concepto | Significado |
|---|---|
0 stdin | Entrada (teclado por defecto). |
1 stdout | Salida normal. |
2 stderr | Errores. |
> equivale a 1>. Descriptores 3+ para casos avanzados.
| Comando | Qué hace | Ejemplo |
|---|---|---|
> | Sobrescribe stdout. | echo hola > out.txt |
>> | Append stdout. | echo mundo >> out.txt |
< | Archivo como stdin. | cat < in.txt |
2> | Solo stderr. | ls x 2> err.txt |
> file 2>&1 | stdout+stderr a file. | cmd > todo.txt 2>&1 |
&> | Atajo bash: ambos. | cmd &> todo.txt |
| | Pipe stdout → stdin. | ls | grep .txt |
echo "hola," > ./salida.txtecho "mundo!" >> ./salida.txtls noExiste 2> errores.txtcomando > todo.txt 2>&1 # errores al mismo sitio que la salidals carpeta_inexistente &> salida.txtls | grep .txtcat y tee
Section titled “cat y tee”cat archivo.txtcat a.txt b.txt > c.txtcat > nuevo.txt # escribir; CTRL+D para terminar
echo "Hola mundo" | tee salida.txt # pantalla + archivols | tee -a lista.txt # appendls | tee a.txt b.txt # varios archivos| Concepto | Significado |
|---|---|
cat | Ver, unir o crear por stdin. |
tee | Escribe a archivo y sigue mostrando en pantalla. |
tee -a | Append. |
Docs: Redirections (Bash).