[opensuse] error Output
I have a script that counts the number of files in a certain directory. The command I use is: NUMFILES=`ls mhc_er* | wc -l` When there are no files, the script returns the message: /bin/ls: bar*: No such file or directory I tried adding 2>/dev/null, but I still get the message. The syntax I used was: NUMFILES=`ls mhc_er* | wc -l` 2>/dev/null What should my syntax be for this line ? I would like to change it on this line inside the script, and not outside the script (I don't want to run ./myscript 2>/dev/null) Dirk *** Disclaimer *** The information contained in this e-mail is confidential and legally privileged and is intended solely for the addressee and to others who have the authority to receive it. Access to this e-mail by anyone else is unauthorized and as such, any disclosure, copying, distribution or any action taken or omitted in reliance on it is unlawful. If you have received this e-mail in error, please notify the sender immediately. The views expressed in this e-mail are the views of the individual sender and should in no way be construed as the views of the Company. The Company is not liable to ensure that outgoing e-mails are virus-free. The Company is not liable, should information or data, for whatever reason, be corrupted or fail to reach its intended addressee. The Company is not liable for any loss or damage of whatsoever nature and howsoever arising resulting from the opening or the use of the information in this e-mail, including its attachments and links. The sender of this e-mail is subject to and bound by the terms and conditions of Company+IBk-s Electronic Communications Usage Policy. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Dirk Moolman wrote:
I have a script that counts the number of files in a certain directory. The command I use is:
NUMFILES=`ls mhc_er* | wc -l`
Maybe you meant "ls -l mhc_er* | wc -l" ?
When there are no files, the script returns the message:
/bin/ls: bar*: No such file or directory
I tried adding 2>/dev/null, but I still get the message. The syntax I used was:
NUMFILES=`ls mhc_er* | wc -l` 2>/dev/null
Try this: NUMFILES=`ls -l mhc_er* 2>/dev/null | wc -l` /Per Jessen, Zürich -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Tuesday 2008-04-22 16:08, Dirk Moolman wrote:
I tried adding 2>/dev/null, but I still get the message. The syntax I used was:
NUMFILES=`ls mhc_er* | wc -l` 2>/dev/null
What should my syntax be for this line ? I would like to change it on this line inside the script, and not outside the script (I don't want to run ./myscript 2>/dev/null)
You'd rather want to use find . -name 'mhc_er*' | wc -l
*** Disclaimer ***
The information contained in this e-mail is confidential and legally privileged and is intended solely for the addressee and to others who have the authority to receive it. Access to this e-mail by anyone else is unauthorized and as such, any disclosure, copying, distribution or any action taken or omitted in reliance on it is unlawful. If you have received this e-mail in error, please notify the sender immediately.
The views expressed in this e-mail are the views of the individual sender and should in no way be construed as the views of the Company.
The Company is not liable to ensure that outgoing e-mails are virus-free.
The Company is not liable, should information or data, for whatever reason, be corrupted or fail to reach its intended addressee.
The Company is not liable for any loss or damage of whatsoever nature and howsoever arising resulting from the opening or the use of the information in this e-mail, including its attachments and links.
The sender of this e-mail is subject to and bound by the terms and conditions of Company’s Electronic Communications Usage Policy.
Disclaimer: By sending me any email through any means, you agree that all your claims are voided. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Jan Engelhardt wrote:
On Tuesday 2008-04-22 16:08, Dirk Moolman wrote:
I tried adding 2>/dev/null, but I still get the message. The syntax I used was:
NUMFILES=`ls mhc_er* | wc -l` 2>/dev/null
What should my syntax be for this line ? I would like to change it on this line inside the script, and not outside the script (I don't want to run ./myscript 2>/dev/null)
You'd rather want to use find . -name 'mhc_er*' | wc -l
But that's not the same. Your statement would also count files in subdirectories, whereas his only in the local directory. To use find to the same effect, one would need to add -maxdepth N to the options; N being 0 or 1, I'd need to read the find man page for that tidbit but am too lazy... ;-) Joachim -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod Email: jschrod@acm.org Roedermark, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Great, thank you very much for all the replies. I used the following in my script, which works very well for me. NUMFILES=`ls mhc_er* 2>/dev/null | wc -l` best regards Dirk -----Original Message----- From: Dirk Moolman [mailto:DirkM@agilitytech.co.za] Sent: 22 April 2008 04:09 PM To: opensuse@opensuse.org Subject: [opensuse] error Output I have a script that counts the number of files in a certain directory. The command I use is: NUMFILES=`ls mhc_er* | wc -l` When there are no files, the script returns the message: /bin/ls: bar*: No such file or directory I tried adding 2>/dev/null, but I still get the message. The syntax I used was: NUMFILES=`ls mhc_er* | wc -l` 2>/dev/null What should my syntax be for this line ? I would like to change it on this line inside the script, and not outside the script (I don't want to run ./myscript 2>/dev/null) Dirk *** Disclaimer *** The information contained in this e-mail is confidential and legally privileged and is intended solely for the addressee and to others who have the authority to receive it. Access to this e-mail by anyone else is unauthorized and as such, any disclosure, copying, distribution or any action taken or omitted in reliance on it is unlawful. If you have received this e-mail in error, please notify the sender immediately. The views expressed in this e-mail are the views of the individual sender and should in no way be construed as the views of the Company. The Company is not liable to ensure that outgoing e-mails are virus-free. The Company is not liable, should information or data, for whatever reason, be corrupted or fail to reach its intended addressee. The Company is not liable for any loss or damage of whatsoever nature and howsoever arising resulting from the opening or the use of the information in this e-mail, including its attachments and links. The sender of this e-mail is subject to and bound by the terms and conditions of Company’s Electronic Communications Usage Policy. -- To unsubscribe, e-mail: opensuse멻윫覷@opensuse.org For additional commands, e-mail: opensuse藩@opensuse.org *** Disclaimer *** The information contained in this e-mail is confidential and legally privileged and is intended solely for the addressee and to others who have the authority to receive it. Access to this e-mail by anyone else is unauthorized and as such, any disclosure, copying, distribution or any action taken or omitted in reliance on it is unlawful. If you have received this e-mail in error, please notify the sender immediately. The views expressed in this e-mail are the views of the individual sender and should in no way be construed as the views of the Company. The Company is not liable to ensure that outgoing e-mails are virus-free. The Company is not liable, should information or data, for whatever reason, be corrupted or fail to reach its intended addressee. The Company is not liable for any loss or damage of whatsoever nature and howsoever arising resulting from the opening or the use of the information in this e-mail, including its attachments and links. The sender of this e-mail is subject to and bound by the terms and conditions of Company’s Electronic Communications Usage Policy.
participants (4)
-
Dirk Moolman
-
Jan Engelhardt
-
Joachim Schrod
-
Per Jessen