?
Solved

redirecting stdout from within ksh script

Posted on 1997-09-04
3
Medium Priority
?
813 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
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 50 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

850 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