Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suppressing command output 1

Status
Not open for further replies.

antmd

Programmer
Feb 8, 2002
3
GB
Hi

I'm a shell script beginner. I use Bash, and have written a simple procedure to check if a named sub-directory exists in a list of directories. I use pushd to change to each directory in turn, and then popd to return to the start directory.

Each 'pushd' and 'popd' writes output (the new directory) to the command-line, which is messy. Is there any way to suppress the output of pushd and popd in particular, and arbitrary commands in general?

Here's the script so far:

project_dirs="$HOME/Projects $HOME/projects"

setproj()
{
shopt -q

for search_dir in $project_dirs; do
pushd $search_dir
if [ -d $1 ]; then
echo "found project $1";
fi
popd
done
}
setproj $1

This produces output like:

~ > bash bashmacro cdr-analyser
~/Projects ~
~/projects ~/Projects ~
found project cdr-analyser
~ >

Thanks!

--Ant
 
<any command> > /dev/null

if you want to suppress error messages too then:

<any command> > /dev/null 2>&1

(file descriptor 1 is standard output; file descriptor 2 is standard error)

Hope this helps, Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top