PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > on ls
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

on ls

Réponse
 
LinkBack Outils de la discussion
Vieux 29/08/2007, 09h47   #1
pincopallo_it@yahoo.it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut on ls

a command like
ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
does not work when there are many files

How can i substitute it ?

  Réponse avec citation
Vieux 29/08/2007, 09h57   #2
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on ls

On 29 Aug., 10:47, pincopallo...@yahoo.it wrote:
> a command like
> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> does not work when there are many files
>
> How can i substitute it ?



Maybe this can you to:
set -o xtrace

After you have set this option every command is displayed how the
shell interpretes it...

  Réponse avec citation
Vieux 29/08/2007, 11h45   #3
Maxwell Lol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on ls

pincopallo_it@yahoo.it writes:

> a command like
> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> does not work when there are many files
>
> How can i substitute it ?


Here's one way

cd $NHBPWDBATCH
ls PWD50*.TXT >> appopippo 2>/dev/null

or

find $NHBPWDBATCH -name 'PWD50*.TXT' >> appopippo 2>/dev/null


  Réponse avec citation
Vieux 29/08/2007, 12h39   #4
pgas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on ls

On Aug 29, 1:45 pm, Maxwell Lol <nos...@com.invalid> wrote:
> pincopallo...@yahoo.it writes:
> > a command like
> > ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> > does not work when there are many files

>
> > How can i substitute it ?

>
> Here's one way
>
> cd $NHBPWDBATCH
> ls PWD50*.TXT >> appopippo 2>/dev/null


This doesn't solve any problem, and on the contrary introduce a bug
if the cd fails.
Plus the output is different.

>
> or
>
> find $NHBPWDBATCH -name 'PWD50*.TXT' >> appopippo 2>/dev/null


This one avoids the expansion of the filenames on the "command line",
and thus will indeed
work with any number of files.
Just take care that 1) it's recursive, 2) if "$NHBPWDBATCH" has a
space it's a good idea to double quote it

with bash (and probably with other shells with a printf builtin) you
can also do:

shopt -s nullgob # so that the expansion returns nothing if no file
are found.
printf "%s\n" "$NHBPWDBATCH"/PWD50*.TXT >> appopippo

  Réponse avec citation
Vieux 29/08/2007, 13h04   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on ls

On Wed, 29 Aug 2007 01:47:28 -0700, pincopallo_it@yahoo.it
<pincopallo_it@yahoo.it> wrote:
>
>
> a command like
> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> does not work when there are many files
>
> How can i substitute it ?
>

ls $NHBPWDBATCH | grep 'PWD50.*\.TXT' >> appopippo 2>/dev/null


--
The goal of science is to build better mousetraps. The goal of nature
is to build better mice.
  Réponse avec citation
Vieux 29/08/2007, 18h13   #6
Michael Tosch
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on ls

Bill Marcum wrote:
> On Wed, 29 Aug 2007 01:47:28 -0700, pincopallo_it@yahoo.it
> <pincopallo_it@yahoo.it> wrote:
>>
>> a command like
>> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
>> does not work when there are many files
>>
>> How can i substitute it ?
>>

> ls $NHBPWDBATCH | grep 'PWD50.*\.TXT' >> appopippo 2>/dev/null
>


More precise is:

\ls $NHBPWDBATCH 2>/dev/null | grep '^PWD50.*\.TXT$' >> appopippo

and with the OP's full-path listing is:

\ls $NHBPWDBATCH 2>/dev/null |
sed -n 's#^PWD50.*\.TXT$#'$NHBPWDBATCH'&#p' >> appopippo

Maybe this works, too:

echo $NHBPWDBATCH/PWD50*.TXT | tr ' ' '\n' >> appopippo

--
Michael Tosch @ hp : com
  Réponse avec citation
Vieux 29/08/2007, 19h50   #7
Cyrus Kriticos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on ls

pgas wrote:
> On Aug 29, 1:45 pm, Maxwell Lol <nos...@com.invalid> wrote:
>> pincopallo...@yahoo.it writes:
>>> a command like
>>> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
>>> does not work when there are many files
>>> How can i substitute it ?

>>
>> find $NHBPWDBATCH -name 'PWD50*.TXT' >> appopippo 2>/dev/null

>
> This one avoids the expansion of the filenames on the "command line",
> and thus will indeed
> work with any number of files.
> Just take care that 1) it's recursive, 2) if "$NHBPWDBATCH" has a
> space it's a good idea to double quote it


find "$NHBPWDBATCH" -maxdepth 1 -name 'PWD50*.TXT' > appopippo 2>/dev/null

--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10767 seconds with 15 queries