Operating System - HP-UX
1845956 Members
2016 Online
110250 Solutions
New Discussion

Re: Shell redirection question

 
Unix Administrator_9
Occasional Contributor

Shell redirection question

In a script I've got something like:
i=`ls *.x *.y *.z`
for j in $i
do

The issue I'm facing at the moment is if one of the file types, eg *.x, doesn't exist I get the message "*.x not found". I've tried redirecting this to /dev/null but I still can't get rid of the message. Any suggestions?

Many Thanks,
Scott Taylor.
3 REPLIES 3
Sundar_7
Honored Contributor

Re: Shell redirection question

Hi Scott,

i=`ls *.x *.y *.z 2>/dev/null'
for j in $i
do

This should work

Sundar
Learn What to do ,How to do and more importantly When to do ?
Unix Administrator_9
Occasional Contributor

Re: Shell redirection question

Thx - I had the the last back quote in the wrong location.

Cheers,
SJT
Bill Hassell
Honored Contributor

Re: Shell redirection question

A simpler way to write this:

for j in $(ls *.x *.y *.z 2>/dev/null)
do
...
done

The use of backticks (grave accent, reverse apostrophe, etc) is deprecated and very easy to misinterpret. $(...) can also be nested if needed.


Bill Hassell, sysadmin