Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

325
Views
Restaurar stdout y stderr al valor predeterminado

En el script de shell, podemos cambiar la entrada predeterminada a un archivo usando el comando exec de la siguiente manera:

 exec 1>outputfile

Sin embargo, si en el mismo script quiero restaurar el descriptor de salida estándar '1' al valor predeterminado (terminal). ¿Cómo podemos lograr eso?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

este ejemplo

Ejemplo 20-2. Redirigir stdout usando exec

 #!/bin/bash # reassign-stdout.sh LOGFILE=logfile.txt exec 6>&1 # Link file descriptor #6 with stdout. # Saves stdout. exec > $LOGFILE # stdout replaced with file "logfile.txt". # ----------------------------------------------------------- # # All output from commands in this block sent to file $LOGFILE. echo -n "Logfile: " date echo "-------------------------------------" echo echo "Output of \"ls -al\" command" echo ls -al echo; echo echo "Output of \"df\" command" echo df # ----------------------------------------------------------- # exec 1>&6 6>&- # Restore stdout and close file descriptor #6. echo echo "== stdout now restored to default == " echo ls -al echo exit 0

aparece para mostrar lo que quieres. Provino del ABS , donde hay una pequeña cantidad de discusión y otra información relevante.

over 4 years ago · Santiago Trujillo Report

0

Pruebe el comando "tee":

 exec | tee outputfile

Mire la página de manual de tee para más explicaciones:

tee: lee desde la entrada estándar y escribe en la salida y los archivos estándar

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!