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.) ...
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...
Why Should you Become an IT Consultant
Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...
Make a Career in Mobile Application Programming
Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...
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