Solved

redirecting stdout from within ksh script

Posted on 1997-09-04
3
787 Views
Last Modified: 2013-12-26
Is it possible to execute an intruction at the top of a ksh script to redirect any further standard output to a file? I want to avoid having to create another script which calls the main script with redirection.
0
Comment
Question by:yppirt090497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Expert Comment

by:onestar
ID: 1294771
Can you give a example of what you are looking (a copy of you script)?
0
 

Accepted Solution

by:
aditya070797 earned 25 total points
ID: 1294772
Hi,
You can do that by enclosing the code in curly braces
and redirecting the output to a file at the closing of the curly braces.

Here is how you can do just that:

Ex: dummy.sh
---------------------------------------------
#!/bin/sh
# Note: open curly-brace:
{
# Do some shell things..
#....
echo "Done some shell things"
# Do some more silly shell things..
# ...
echo "Done some more silly shell things.."
# Done; close curly brace.
} >dummy.out 2>&1
# The above line should redirect both stdout and stderr
# of the preceding script to a file dummy.out  
---------------------------------------------




0
 

Author Comment

by:yppirt090497
ID: 1294773
Tested and it works nicely.

I was also sent another solution which uses 'exec'.

exec 1>foo
exec 2>foo
echo "test redirect"
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 98
Expand data scrubbing tool 13 36
while loop over for loop 7 116
Problem to Office 1 45
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question