suppress 'ls' error output

When I run 'ls *.c' (for example), and there are no files with .c extension in the directory, I get the following output: "/bin/ls: No match".
This is very nice, but nothing would please me more than making 'ls' shut up when there are no files to show.
sharone_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sharone_Author Commented:
How do I make that happen?
0
dircCommented:
There is no option that keeps 'ls' silent when there are no matching files. The only solution is to direct the standard error output to someplace like /dev/null, while keeping the standard output to your console.

In Bourne shell (/bin/sh) or Korn shell (/bin/ksh), you can do:

ls *.c 2> /dev/null

Any files that match the *.c pattern will appear as normal. If there are no matching files, nothing will appear.

I don't know of any good solution in C shell (/bin/csh).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RandybCommented:
you could actually write a little filter script that you would run inplace of ls (maybe named lsc for custom ?) it could check for output
and if none then pipe the echo out to /dev/null, otherwise return the output to the standard out (screen ... ).

EH ... I wouldnt bother myself but if the output really bugs you or if you are running it inside another app then at least this is a way to go.
0
RandybCommented:
sorry dirc,
sometimes you read something and yet do not see .
I think I basically mimiced what you said (just a different approach) ...but yeah you're right.

Have fun !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.