Solved

redirecting stdout from within ksh script

Posted on 1997-09-04
3
800 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 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