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 > Can anybody make some summery here?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Can anybody make some summery here?

Réponse
 
LinkBack Outils de la discussion
Vieux 05/12/2006, 03h17   #1
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Can anybody make some summery here?

Hi,
I have get invovled in shell programming for a
month. And I have written some utility script.
But now, there are still some points I can't
clearly figure out. They are:

1.when process filenames, how to do with space,tab,
and other special charactors in it so that it will
not infllence the command excuting rightly?

2.when I use regular expression in the grep, perl, sed.
awk commands, I feel there are some differences in
them. Could anyone point them out or give me some
document to find what they are?

Any indication and will be appreciated greatly!
Thanks in advance!
  Réponse avec citation
Vieux 05/12/2006, 07h34   #2
RolandRB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can anybody make some summery here?


Bo Yang wrote:
> Hi,
> I have get invovled in shell programming for a
> month. And I have written some utility script.
> But now, there are still some points I can't
> clearly figure out. They are:
>
> 1.when process filenames, how to do with space,tab,
> and other special charactors in it so that it will
> not infllence the command excuting rightly?


It is best to refer to your file names in double quotes (double quotes
so a file name variable will get resolved) so that any special
characters are protected by the double quotes and so the whole file
name is referred to. Like this:

for file in "$@" ; do
if [ -e "$file" etc...

> 2.when I use regular expression in the grep, perl, sed.
> awk commands, I feel there are some differences in
> them. Could anyone point them out or give me some
> document to find what they are?


Can't you with that one.

> Any indication and will be appreciated greatly!
> Thanks in advance!


  Réponse avec citation
Vieux 05/12/2006, 08h58   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can anybody make some summery here?

2006-12-05, 11:17(+08), Bo Yang:
> Hi,
> I have get invovled in shell programming for a
> month. And I have written some utility script.
> But now, there are still some points I can't
> clearly figure out. They are:
>
> 1.when process filenames, how to do with space,tab,
> and other special charactors in it so that it will
> not infllence the command excuting rightly?


Remember to always quote variables. An unquoted variable has a
very special meaning to the shell, you should never do that
unless you know what you're doing and why.

file="/path to whatever
with newlines and 'quotes'
and \@*?%\" characters'

touch -- "$file"
cmd -a -b -- "$file"

> 2.when I use regular expression in the grep, perl, sed.
> awk commands, I feel there are some differences in
> them. Could anyone point them out or give me some
> document to find what they are?

[...]

standard grep, expr, sed, more, vi, ed, pax, ex, csplit, nl use
BRE (basic regular expressions). awk and grep -E (formerly
egrep) use ERE (extended regular expressions). lex uses ERE with
additions/restrictions.

See
http://www.opengroup.org/onlinepubs/...bd_chap09.html
for the standard for BRE and ERE.

Some implementations of those tools have extensions over the
standard that you shouldn't use in scripts but should be
described in their respective manuals.

perl has its own regexps (also found (similar) in tools that use
the PCRE library as/or in php, newer TCLs, zsh, exim, apache and
more). Run "perldoc perlre" or "man perlre".

vim has yet another sort of regular expressions that provide
with the same functionalities as perl's but with a different
syntax. AT&T ksh has AT&T regexps support...

--
Stéphane
  Réponse avec citation
Vieux 05/12/2006, 13h26   #4
Bo Yang
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can anybody make some summery here?

Stephane CHAZELAS :
> 2006-12-05, 11:17(+08), Bo Yang:
>> Hi,
>> I have get invovled in shell programming for a
>> month. And I have written some utility script.
>> But now, there are still some points I can't
>> clearly figure out. They are:
>>
>> 1.when process filenames, how to do with space,tab,
>> and other special charactors in it so that it will
>> not infllence the command excuting rightly?

>
> Remember to always quote variables. An unquoted variable has a
> very special meaning to the shell, you should never do that
> unless you know what you're doing and why.
>
> file="/path to whatever
> with newlines and 'quotes'
> and \@*?%\" characters'
>
> touch -- "$file"
> cmd -a -b -- "$file"
>
>> 2.when I use regular expression in the grep, perl, sed.
>> awk commands, I feel there are some differences in
>> them. Could anyone point them out or give me some
>> document to find what they are?

> [...]
>
> standard grep, expr, sed, more, vi, ed, pax, ex, csplit, nl use
> BRE (basic regular expressions). awk and grep -E (formerly
> egrep) use ERE (extended regular expressions). lex uses ERE with
> additions/restrictions.
>
> See
> http://www.opengroup.org/onlinepubs/...bd_chap09.html
> for the standard for BRE and ERE.
>
> Some implementations of those tools have extensions over the
> standard that you shouldn't use in scripts but should be
> described in their respective manuals.
>
> perl has its own regexps (also found (similar) in tools that use
> the PCRE library as/or in php, newer TCLs, zsh, exim, apache and
> more). Run "perldoc perlre" or "man perlre".
>
> vim has yet another sort of regular expressions that provide
> with the same functionalities as perl's but with a different
> syntax. AT&T ksh has AT&T regexps support...
>

Thank you, I have get it!
  Réponse avec citation
Vieux 05/12/2006, 14h29   #5
Geoff Clare
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Can anybody make some summery here?

Stephane CHAZELAS <this.address@is.invalid> wrote, on Tue, 05 Dec 2006:

>> 2.when I use regular expression in the grep, perl, sed.
>> awk commands, I feel there are some differences in
>> them. Could anyone point them out or give me some
>> document to find what they are?

> [...]
>
> standard grep, expr, sed, more, vi, ed, pax, ex, csplit, nl use
> BRE (basic regular expressions). awk and grep -E (formerly
> egrep) use ERE (extended regular expressions). lex uses ERE with
> additions/restrictions.


awk uses a modified form of ERE where backslash escapes are
recognised as in C string literals.

For example in awk, [ \t] matches a space or a tab, whereas with
grep -E it matches a space, backslash or 't'.

--
Geoff Clare <netnews@gclare.org.uk>

  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 13h27.


É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 3,32333 seconds with 13 queries