|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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! |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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! |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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> |
|
![]() |
| Outils de la discussion | |
|
|