home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 15.2 Filename Wildcards in a Nutshell Chapter 15
Wildcards
Next: 15.4 What if a Wildcard Doesn't Match?
 

15.3 Adding { } Operators to Korn (and Bourne) Shells

The bash and C shell curly brace operators ( 9.5 ) are handy for working with strings. Some versions of the Korn shell can be configured to make these work. [2] If your Korn shell can't do that, or if you use the Bourne shell, you can use the shell function ( 10.9 ) called qcsh . (You can rewrite it as a shell script ( 44.2 ) if your shell doesn't have functions.) It writes the command line you type into a temporary file, then gives the file to the C shell. [3] Type qcsh , a space, and the command line you want to run. Here are two examples from article 9.5 : to fix a typo in a filename (change fixbold61.c to fixbold6.c ):

[2] If your system has Korn shell sources, your system administrator can edit the file OPTIONS and set BRACEPAT=1 , then recompile.

[3] In some versions of UNIX, passing the command line to the C shell with csh   -fc   "$@" wouldn't expand the braces. That's why I used a temporary file.

$ 

qcsh mv fixbold{61,6}.c

To edit ten new files that don't exist yet:

$ 

qcsh vi /usr/foo/file{a,b,c,d,e,f,g,h,i,j}

Here's the function:







-f
 


qcsh()
{
    echo "$@" > /tmp/q$$
    csh -f /tmp/q$$
    rm -f /tmp/q$$
}

- JP


Previous: 15.2 Filename Wildcards in a Nutshell UNIX Power Tools Next: 15.4 What if a Wildcard Doesn't Match?
15.2 Filename Wildcards in a Nutshell Book Index 15.4 What if a Wildcard Doesn't Match?

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System