Unix Shell - problems with quoting

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2005 > problems with quoting





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author problems with quoting
Mark P

2005-10-25, 5:53 pm

I'm trying to write a little alias (in tcsh) to display the .h and .cpp
files in a directory. I can do this at the command line as:

find . -maxdepth 1 | egrep '\.(h|cpp)$'

When I try to define this as an alias however:

alias srcfind "find . -maxdepth 1 | egrep '\.(h|cpp)$'"

I get "Illegal variable name." I believe this is because of the $ but I
can't figure how to prevent the shell from trying to expand this. Any
suggestions?

Thanks,
Mark
Christophe Gaubert

2005-10-25, 5:53 pm

Mark P a écrit :
> I'm trying to write a little alias (in tcsh) to display the .h and .cpp
> files in a directory. I can do this at the command line as:
>
> find . -maxdepth 1 | egrep '\.(h|cpp)$'


Why not :
ls *.cpp *.h
?


--
Christophe Gaubert
http://perso.wanadoo.fr/christophe.gaubert
Mail posté depuis un système libre GNU/Linux
Michael Tosch

2005-10-25, 5:53 pm

Mark P wrote:
> I'm trying to write a little alias (in tcsh) to display the .h and .cpp
> files in a directory. I can do this at the command line as:
>
> find . -maxdepth 1 | egrep '\.(h|cpp)$'
>
> When I try to define this as an alias however:
>
> alias srcfind "find . -maxdepth 1 | egrep '\.(h|cpp)$'"
>
> I get "Illegal variable name." I believe this is because of the $ but I
> can't figure how to prevent the shell from trying to expand this. Any
> suggestions?
>



alias srcfind "find . -maxdepth 1 | egrep '\.(h|cpp)"\$"'"

seems to work - the $ is \escaped outside the "string".

However, your expression is faster and more precise with

find . -maxdepth 1 \( -name '*.h' -o -name '*.cpp' \)

or

ls -1 *.h *.cpp

--
Michael Tosch @ hp : com
Mark P

2005-10-25, 5:53 pm

Christophe Gaubert wrote:
> Mark P a écrit :
>
>
>
> Why not :
> ls *.cpp *.h
> ?
>
>

Why not indeed. As you can see I'm quite a newb. Thanks for the tip.
Mark P

2005-10-25, 5:53 pm

Michael Tosch wrote:
> Mark P wrote:
>
>
>
> alias srcfind "find . -maxdepth 1 | egrep '\.(h|cpp)"\$"'"
>
> seems to work - the $ is \escaped outside the "string".
>
> However, your expression is faster and more precise with
>
> find . -maxdepth 1 \( -name '*.h' -o -name '*.cpp' \)


Thanks. I hadn't known about the boolean options.

>
> or
>
> ls -1 *.h *.cpp
>


As always, I miss the obvious

Thanks,
Mark
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com