Tcsh notes

From raju

get the last word of the previous command

Use !$ to get the last word of the previous command, !* to get all arguments of the previous command. For example

    > cat junk.txt
    >grep abc junk.txt
    >grep aBc !$
    grep aBc junk.txt
    >grep -i !*
    grep -i aBc junk.txt

tags | word designators

Machine hangs after logging in

Issue:- After logging into a Linux machine via ssh, the connection hangs after successful login.

Using username "XXXX".
Authenticating with public key "YYYYYYYYYY"
Last login: Fri Sep 26 22:58:42 2014 from ZZZ.ZZZ.ZZZ.ZZZ

If I press ctrl-c, I am logged in. Same thing happens if I try to exit (the exit command succeeds, but the connection is not closed until I press ctrl-c).

I am running tcsh shell on the Linux machine. The problem persists even after moving ~/.cshrc

=> mv .cshrc .cshrc_raju_20140925

Solution:- Fixed the issue by (re)moving .history file

=> mv .history .history_raju_20140925

Further Reading:

  • man tcsh -> section on "Startup and shutdown"

Colors in ls

Add the following lines to ~/.cshrc

set color
alias ls 'ls -F --color'

Then source it.

source ~/.cshrc

Running ls after this will display colors.

Further Reading:

set environment variable

Create a script

=> cat host.tcsh
set host=`hostname`
set username=`whoami`
setenv hu ${username}@${host}

source it

=> source host.tcsh

Test it

=> echo $hu

check if a file exists

    if ( -f file.txt ) then
        echo "$foo exists"
        echo "$foo does not exist"

Weird characters when reverse searching

<CTRL-r>, right arrow results in weird characters -

The solution is to use ESC to end the search. For example control-r, some characters to reverse search in the command history, escape key.

String manipulation describes it well.