Learn UNIX Certification from the Best Tutors
Search in
I have a bash application that is producing some result, and I'd like to echo the result to either stdout
or to a user chosen file. Because I also echo other interactive messages going to the screen, requiring the user to explicitly use the >
redirection when he wants to echo the result to a file is not an option (*), as those messages would also appear in the file.
Right now I have a solution, but it's ugly.
if [ -z $outfile ]
then
echo "$outbuf" # Write output buffer to the screen (stdout)
else
echo "$outbuf" > $outfile # Write output buffer to file
fi
I tried to have the variable $outfile
to be equal to stdout
, to &1
and perhaps something else but it would just write to file having that name and not actually to stdout. Is there a more elegant solution?
(*) I could cheat and use stderr
for that purpose, but I think it's also quite ugly, isn't it?
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Top 12 IT Certifications
It is a fact that premium pay for IT certifications had been on decline since past few years but it has shown a dramatic rise since last two quarters and is up by around 1.5 percent. This is the largest increase for a quarter since 2006. Below is the list of top 12 IT certifications which are predicted to grow in 2014. 1.) ...
Make a Career as a BPO Professional
Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...
Top 5 Skills Every Software Developer Must have
Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today. In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...
Learn Hadoop and Big Data
Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...
Looking for UNIX Certification classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for UNIX Certification Classes are on UrbanPro
The best Tutors for UNIX Certification Classes are on UrbanPro