What is the @Echo Off alternative for a shell script?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You need to redirect the stdout and stderr of the apt-get update to some where else besides the screen.
IF you really don't want (or need) to ever see any output. Then you can redirect to /dev/null.
You can do it from inside the script itself, using exec. For example:
Code:
#!/bin/bash
exec > /dev/null 2>&1
will redirect both the standard output and the standard error to /dev/null and every subsequent command will be affected. If you still want to preserve the output of some commands, as in your example, better to explicitly redirect the standard output of the commands you want to hide, e.g.
An aside note: if I remember well in DOS the @ECHO OFF statement, does not hide the output of the commands (correct me if I'm wrong), but the print out of the command itself. In unix shells this is not the default behaviour, but you can trigger it using the -x option:
Code:
#!/bin/bash -x
this will show you every command that is going to be executed, useful for debugging purposes.
You need to redirect the stdout and stderr of the apt-get update to some where else besides the screen.
IF you really don't want (or need) to ever see any output. Then you can redirect to /dev/null.
Example:
Code:
apt-get update 2>&1 >/dev/null
--ET
cool, so if I wanted to save the output to a txt file I assume this would work?
You need to redirect the stdout and stderr of the apt-get update to some where else besides the screen.
IF you really don't want (or need) to ever see any output. Then you can redirect to /dev/null.
Example:
Code:
apt-get update 2>&1 >/dev/null
--ET
Just a note here: the order of redirections is important. This statement does not redirect standard error to /dev/null, since stderr is redirected to stdout when this one still points to the terminal. The correct way is:
cool, so if I wanted to save the output to a txt file I assume this would work?
replica88, yes... /dev/null is a kind of black hole in unix systems, but you can redirect to a file as well. Have a look at bash documentation, as previously suggested. Here is the I/O redirection chapter of the Advanced Bash Scripting Guide.. a bit difficult to read for beginners, but useful to take as a reference. Other documentation is available on www.tldp.org.
Just a note here: the order of redirections is important. This statement does not redirect standard error to /dev/null, since stderr is redirected to stdout when this one still points to the terminal. The correct way is:
Code:
command > /dev/null 2>&1
Just for sake of the original poster...
Ooops ! You correct.
It's still early in the morning for me.
Distribution: Ubuntu 14.04, Windows 8, Windows Server 2012. Ubuntu Server 14.04
Posts: 196
Rep:
Suppressing output of script to terminal
Quote:
Originally Posted by colucix
You can do it from inside the script itself, using exec. For example:
Code:
#!/bin/bash
exec > /dev/null 2>&1
will redirect both the standard output and the standard error to /dev/null and every subsequent command will be affected. If you still want to preserve the output of some commands, as in your example, better to explicitly redirect the standard output of the commands you want to hide, e.g.
Placing this at the top of the Script suppresses all output to the terminal Thank you! Sorry about posting on such an old thread but it took me awhile to find this good solution and I hope I can help others as well!
Last edited by EODSteven; 10-01-2012 at 06:57 AM.
Reason: added reason for late post
Yes, it's not usually advised to open up an old thread unless you have something substantive to add to that discussion. But it's nice to hear that it helped you.
By the way, also check the options for the commands you use. Very often they include some way to disable output. The most common flags for this are probably -q (quiet) and -s (silent).
In this case "apt-get update -q=2" appears to turn off the default output.
Last edited by David the H.; 10-01-2012 at 12:12 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.