user4501715
user4501715

Reputation:

How to suppress output of command in shell script?

For example:

cat a.txt
1 2
1 6    

{ cat $HOME/SANITY/file.txt | grep 1 >> $HOME/SANITY/new.txt } > /dev/null

cut -d' ' -f2

Now i don't want the results to be shown when running the script with this code.

Upvotes: 7

Views: 9360

Answers (2)

Simply use in your case :

grep 1 "$HOME/SANITY/file.txt" >> "$HOME/SANITY/new.txt"

And for general purpose :

command_foo_bar > /dev/null # or any other non special file

Upvotes: 1

Nidhoegger
Nidhoegger

Reputation: 5232

You can redirect the output. if you only use your_command > /dev/null only stdout will be redirected. If you want to remove the output of stderr as well, redirect stderr to stdout and stdout to /dev/null using:

your_command > /dev/null 2>&1

2>&1 will move stderr to the file descriptor of stdout.

Upvotes: 11

Related Questions