specifying back-ticks in an alias (csh/tcsh)

specifying back-ticks in an alias (csh/tcsh)

Post by Terry Carro » Fri, 13 Jun 1997 04:00:00



I use the following command to find large files for me to consider
deleting, compressing or offloading when I come near my quota:

    ls -pal `find ~/  -size +300000c` | sort -r +3

It works like a champ, giving me a list of my files over 300K, sorted
largest to smallest.  (Actually, I sometimes also pipe into more or
head to just get a further subset, but that's not material to the rest
of this post.)

I would like to set this up as an alias to, for example, a name like
"findbig".  I've tried the following:

   alias findbig "ls -pal `find ~/  -size +300000c` | sort -r +3"

Unfortunately, but obviously in retrospect, this executes the find at
the time I set the alias, so when I try to use my "findbig" alias, it
selects the files that were over 300K at the time I set the alias, not
at the time I execute the findbig.

(it looks something like "ls -pal path1 path2 path3 | sort -r +3")

Okay, so the backticks need to be escaped, right?  Well, I tried this:

  alias findbig "ls -pal \`find ~/  -size +300000c\` | sort -r +3"

Now, the alias amounts to:

  ls -pal \ | sort -r +3

This has me completely confused.

I thought I might have to escape the backslash itself, but that didn't
help any.  When I added 2 backslashes, one before each of the
backslashes already there, I just get:

 ls -pal \\ | sort -r +3

and adding further backslashed act correspondingly.

My question is: how the heck do I specify a backticked command in an
alias?  

A related question is, would it matter if I put the alias
specification in a .login or .cshrc file or a file that's sourced at
login time?  (I typically include my aliases in a .alias file that is
sourced from my .cshrc)

The man page is not particularly helpful.  It says

                                               def is a list of words
     that  may  contain  escaped history-substitution metasyntax.

I realize I have to do some escaping here, but how is my mystery.

I'm running tcsh 6.06.00.

Of course, if someone has a simple way to list the names and sizes of
one's largest files without backticking, I'd be happy to use that.
But I'm still interested in why the backticking approach isn't
working.

 
 
 

specifying back-ticks in an alias (csh/tcsh)

Post by Francois Deryc » Fri, 13 Jun 1997 04:00:00



> I use the following command to find large files for me to consider
> deleting, compressing or offloading when I come near my quota:

>     ls -pal `find ~/  -size +300000c` | sort -r +3

> It works like a champ, giving me a list of my files over 300K, sorted
> largest to smallest.  (Actually, I sometimes also pipe into more or
> head to just get a further subset, but that's not material to the rest
> of this post.)

The following line works and can be aliased :

find ~/ -size +300000c | xargs ls -pal | sort -r -n -k 1.29,1.41

Slad.
--

        (o o)                  http://www.tele.ucl.ac.be/PEOPLE/fd.html
-----oOO-(_)-OOo-------------------------------------------------------
Ir. Fran?ois Deryck - Research Assistant       Phone : +32 10 47 80 71
UCL - Universit Catholique de Louvain                 +32 10 47 23 00
Communications and Remote Sensing Laboratory    Fax   : +32 10 47 20 89
-----------------------------------------------------------------------

 
 
 

specifying back-ticks in an alias (csh/tcsh)

Post by Terry Carrol » Fri, 13 Jun 1997 04:00:00


[posted and mailed]


> The following line works and can be aliased :

> find ~/ -size +300000c | xargs ls -pal | sort -r -n -k 1.29,1.41

Thank you, Francois.  That's exactly what I needed.  Someone else emailed
me the following suggestion, which also works:

  find ~/ -size +300000c -exec ls -pal {} \; | sort -r +3

I think Francois' version is a tad more efficient, because there's only
one ls instead of one for each file found.

I'm still curious about how to escape backticks in an alias command,
though.  That curiousity is academic now that I have a solution, but I am
still curious if anyone else knows the answer.

--
Terry Carroll       | "The invention provides means for continuously
Santa Clara, CA     | trapping sparrows and supplying a cat and

Modell delenda est  |                - U.S. Patent no. 4,150,505

 
 
 

specifying back-ticks in an alias (csh/tcsh)

Post by Bill Tott » Mon, 16 Jun 1997 04:00:00



 <...>

Quote:>I would like to set this up as an alias to, for example, a name like
>"findbig".  I've tried the following:

>   alias findbig "ls -pal `find ~/  -size +300000c` | sort -r +3"

>Unfortunately, but obviously in retrospect, this executes the find at
>the time I set the alias, so when I try to use my "findbig" alias, it
>selects the files that were over 300K at the time I set the alias, not
>at the time I execute the findbig.

 <...>

I do not usually halp [t]csh users because I feel the it is their
fault if they are having problems if they are using a non-bourne-style shell.
But anyway, use single quotes('):

alias findbig 'ls -pal `find ~/  -size +300000c` | sort -r +3'
--
Totten, William David (Bill)         Computer and Information Science Major

http://pobox.com/~totten/               Friends don't let friends use emacs

 
 
 

specifying back-ticks in an alias (csh/tcsh)

Post by Veksler Micha » Thu, 19 Jun 1997 04:00:00


: [posted and mailed]


: > The following line works and can be aliased :
: >
: > find ~/ -size +300000c | xargs ls -pal | sort -r -n -k 1.29,1.41

: Thank you, Francois.  That's exactly what I needed.  Someone else emailed
: me the following suggestion, which also works:

:   find ~/ -size +300000c -exec ls -pal {} \; | sort -r +3

: I think Francois' version is a tad more efficient, because there's only
: one ls instead of one for each file found.

: I'm still curious about how to escape backticks in an alias command,
: though.  That curiousity is academic now that I have a solution, but I am
: still curious if anyone else knows the answer.

alias grepls 'ls -l `grep -l \!*`'

This is *NOT THE SAME* as:
  alias grepls 'grep -l \!* | xargs ls -l`'

In this case color-ls will not color your files.

Michael

 
 
 

1. Sed and possible double back-ticks -- great alias gone to hell

Greetings,

 I'm curious as to why this works:

echo `pwd` | sed -e 's#WebServer#WebServerTest#g'

(It will of course take my current directory, replace the WebServer with
WebServerTest, and display to standard output.)

But this doesn't:

DIR=`echo `pwd` | sed -e 's#WebServer#WebServerTest#g'`  ; cd ${DIR}

Here, it should theoretically take that current directory, replace teh
WebServer with WebServerTest, and redirect the output to the assignment of
the DIR variable, which will then let me cd there.

This would make a wonderful alias.  So why doesn't it work?  Because there
are double back-ticks?  Ok, fine, how do I get around that (if that is in
fact the reason)?

Matt

2. SCSI Card Not Found

3. Help to find a good book on csh/tcsh to teach myself csh/tcsh script

4. sendmail listen on ip alias

5. alias in csh tcsh

6. compiling emacs 19.27 for solaris2.3

7. Thanks :alias in csh and tcsh

8. Linker errors in wine-980601 (Repost)

9. tcsh/csh expression alias redone for bash

10. limits on env, alias or path in csh /tcsh ?

11. can you alias a complete foreach in csh/tcsh

12. alias probem in tcsh and csh

13. Deleting files / useful aliases (was TCSH CSH BASH.....)