ALIAS in an csh

ALIAS in an csh

Post by Schwitter Rued » Fri, 04 Oct 1996 04:00:00



Hy

I use csh to make little scripts. I have customized my .cshrc
to have short-cuts for many commands.
I have try to use this alias in an script, but the only thing
I became was:

ppr: command not found

How can I use alias in csh-scripts?

Thanks in advance.

--
Regards Ruedi

----------------------------------------------------------------

Haselstrasse                            Fax: ++41 56 205 54 66
5400 Baden
---------------------------------------------------------------

 
 
 

ALIAS in an csh

Post by Brian S Hil » Sat, 05 Oct 1996 04:00:00


Schwitter Ruedi (Ruedi.Schwit...@chinf.mail.abb.com) wrote:

: I use csh to make little scripts. I have customized my .cshrc
: to have short-cuts for many commands.
: I have try to use this alias in an script, but the only thing
: I became was:
: ppr: command not found
: How can I use alias in csh-scripts?

syntax: alias [alias-name [alias-substitution-string(s)]]

\!^     first argument that the user or script supplied.
\!:1    first argument that the user or script supplied.
\!:2    first argument that the user or script supplied.
\!$     last argument that the user or script supplied.
\!*     all argument(s) that the user or script supplied.

There is (a lot) more, but you should have read the man pages on csh
before you submitted this post. Do so now.

Here is the example file of more login configuration than anyone will
ever want, found in the O'Reilly and Assoc archive from their "Unix
Power Tools" book:

##
## COPY THIS FILE INTO $HOME/.login (OR EQUIVALENT),
## UNCOMMENT WHAT YOU NEED.

## TIME IN ANOTHER TIME ZONE:
##
#alias tm '(setenv TZ \!$; date )'

## MULTI-LINE SHELL PROMPTS:
##
## This sets a three-line prompt: one blank line, one line with the hostname
## and current directory, and a third with the history number and a
## percent sign.  This should be placed in your .cshrc file.
##
## The prompt will look something like:
## <blank line>
## username@hostname current_directory
## history_number %
#
#set hostname=`hostname`
#alias setprompt 'set prompt="\\
#${hostname:h}:${cwd}\\
#\! % "'
#alias cd 'chdir \!* && setprompt'
#setprompt           # to set the initial prompt

## HOST:CWD IN VT102 STATUS LINE:
##
## VT102 alias: puts $host:$cwd in status line. Escape sequences are:
## ${e}7 = save cursor position, ${e}[25;1f = move to start of status line
## (line 25), ${e}[0K = erase line, ${e}8 = restore cursor
#
#set e="`echo -n x | tr x \\033`"        # MAKE AN ESCAPE CHARACTER
#set host=`hostname`
#alias cd 'chdir \!* && echo -n "${e}7${e}[25;1f${e}[0K${host:h}:${cwd}${e}8"'

## HIGHLIGHTED PROMPT:
##
## Make a blinking prompt.  This example makes the prompt:
## root:hostname
## with `root' blinking.
##
## Put ESCape character in $e.  Use to start blinking mode (${e}[5m)
## and go back to normal mode (${e}[0m) on VT100-series terminals:
#
#set e="`echo -n x | /bin/tr x \\033`"
#set prompt="${e}[5mroot${e}[0m@`/bin/hostname`# "

## DIRECTORY STACK IN PROMPT:
##
## This makes a multi-line prompt that shows the directory stack.  These
## commands should be put in your .cshrc file.
##
## The prompt will look something like:
## <blank line>
## username@hostname directory_stack
## history_number %
##
## The pushd and popd commands are used to push and pop directories
## onto the stack.
##
## This makes a blank line before each prompt; to avoid that, join the
## first and second lines of the setprompt alias.
#
## PUT hostname.domain.name IN $hostname AND hostname IN $HOST:
#set hostname=`hostname`
#setenv HOST `expr $hostname : '\([^.]*\).*'`
#alias setprompt 'set prompt="\\
#${USER}@${HOST} `dirs`\\
#\! % "'
#alias cd  'chdir \!* && setprompt'
#alias pushd  'pushd \!* && setprompt'
#alias popd  'popd  \!* && setprompt'
#setprompt       # SET THE INITIAL PROMPT

## TAIL OF DIRECTORY STACK IN PROMPT:
##
## This alias shows only the tail of each path in the dirs output.  
##
## The C shell :gt globally edits all words, leaving the tail of each pathname:
##
## The prompt will look something like:
## <blank line>
## username@hostname tailed_directory_stack
## history_number %
#
#alias setprompt 'set dirs=(`dirs`); set prompt="\\
#${USER}@${HOST} $dirs:gt\\
#\! % "'

## QUOTING RIGHT IN ALIASES:
##
## quote and makealias -- Get quoting right in csh aliases
#
#alias quote     "/bin/sed -e 's/\\!/\\\\\!/g' -e 's/'\\\''/'\\\'\\\\\\\'\\\''/g' -e 's/^/'\''/' -e 's/"\$"/'\''/'"
#alias makealias "quote | /bin/sed 's/^/alias \!:1 /' \!:2*"

## HISTORY EDITING:
##
## Aliases used for command line editing in csh with the ex editor:
## "le" stands for "edit last command".
## "he" stands for "edit history number"
##      For example: he !121 will edit the 121st history command.
## "he" may also be used to edit an arbitrary string which then gets sourced.
## "redo" will allow you to re-edit the last command you edited.
#
#alias he 'echo \!*:q > ~/.cmd; ex - +open ~/.cmd; source ~/.cmd'
#alias le 'echo \!-1:q > ~/.cmd;ex - +open ~/.cmd; source ~/.cmd'
#alias redo 'ex - +open ~/.cmd; source ~/.cmd'

## HISTORY EDITING WITH MCED:
##
## Use this alias with the mced program.
#
#alias = "history -h 50 >\e! /tmp/eh$$;mced \e!*; source -h /tmp/ec$$; source /tmp/ec$$;/bin/rm /tmp/ec$$"

## HOW TO USE IF/THEN/ELSE IN ALIASES:
##
#alias C 'eval "if (\!* =~ *.c) then \\
#       echo "C quitting: no .c on end of \!* please." \\
#else \\
#       if (-e \!*) mv \!* \!*.old \\
#       echo \!*.c SENT TO cc \\
#       cc -s \!*.c -o \!* \\
#       if (-e \!*) chmod 311 \!* \\
#endif"'
#

## ABBREVIATED PATHNAMES:
##
## cd with abbreviated pathnames -- Just type the initials (first
## letter, or more) of each directory in the pathname, starting at the
## root direcctory.  Put a period after each part.
##   eg: c u.i.h.  might match with /usr/include/hsfs
##
## THIS VERSION PRINTS No match IF NO MATCH, BUT cd ALIAS WON'T WORK...
#alias c 'set d=`echo \!^* | sed "s/\([^.]*\)\./\/\1*/g"`/; echo $d; \\
#       if ("$d" == "") echo No match.; if ("$d" != "") cd $d'

## ABBREVIATED PATHNAMES WITH CD ALIAS:
##
## cd with abbreviated pathnames -- Just type the initials (first
## letter, or more) of each directory in the pathname, starting at the
## root direcctory.  Put a period after each part.
##   eg: c u.i.h  might match with /usr/include/hsfs
##
## THIS VERSION WORKS WITH cd ALIAS, BUT DOUBLE cd AT THE END IS A KLUDGE:
#alias c 'set d=`echo \!^* | sed "s/\([^.]*\)\./\/\1*/g"`/; echo $d; \\
#       if ("$d" == "") echo No match.; if ("$d" != "") chdir $d; cd .'

## SYMLINKS WITHOUT HARDPATHS:
## If your system has symbolic links but your shell doesn't recognize a
## variable like hardpaths, these are work-arounds for your .cshrc file:
##
## When you cd, this alias re-sets the cwd variable to the output of
## /bin/pwd, then resets the prompt to the new cwd.  Using pushd or popd
## runs the cd alias too -- this changes to the current directory (.),
## which fixes cwd (as well as the dirs command) and resets the prompt.
#
#alias setprompt 'set prompt="${cwd}% "'
#alias cd        'chdir \!* && set cwd=`/bin/pwd` && setprompt'
#alias pushd     'pushd \!* && cd .'
#alias popd      'popd \!* && cd .'

## RUN COMMANDS WHEN ENTERING/LEAVING A DIRECTORY:
##
## Automatic Setup When You Enter and Exit A Directory
##
## When you cd into a directory and a file named `.enter' exists,
## the commands in it will be run by your current shell.
## When you leave a directory and a file named `.exit' exists,
## the commands in it will be run by your current shell.
#
#alias cd 'if (-o .exit) source .exit; chdir \!*; if (-o .enter) source .enter'

## MATCH FILES STARTING WITH '.'
##
## variable with wildcards to match all names starting with "."
#set dots=".??* .[`echo Y--/-Z | tr YZ \\001\\177`]"

## COMPARE MODIFICATION TIMES:
##
## compare modification times of /etc/motd and ~/.hushlogin to see
## which is newer.  If /etc/motd is newer, show it.
#
## list files by time (most recently modified file first)
#set files=(`ls -t /etc/motd ~/.hushlogin`)
#
## If /etc/motd is the first file in $files, then it's newer
#if ( $files[1] == /etc/motd ) then
#    cat /etc/motd
#    touch ~/.hushlogin
#endif
#unset files
#

## DIR ALIAS FOR DOS USERS:
##
## 'dir'
## Simple `dir' alias for DOS converts
#
#alias dir 'echo Hey! This is UNIX! \\
#        Well, okay... but just this once...; ls -l'
#

## FIND TEXT FILES IN CURRENT DIRECTORY:
##
#alias findtext 'perl -le '\''-T && print while $_ = shift'\'' *'

## FIND FILES IN CURRENT DIRECTORY:
##
## Find files only in the current directory with -prune
#
## print using -print (complete path name only)
#alias find. 'find . \( -type d ! -name . -prune \) -o \( \!* -print \)'
#
## print using -s (gives output similar to `ls -gilds')
#alias find.ls 'find . \( -type d ! -name . -prune \) -o \( \!* -ls \)'

## APPEND DATE TO A NEW FILENAME:
##
#alias vid "vi \!:1.`date +%m.%d`"

## CHANGE YOUR UMASK:
##
## Aliases to alter your umask
##
## With these two values of umask, new files and directories will have
## permissions of 775 or 755, respectively.
#
#alias open umask 002
#alias shut umask 022

## CHANGE PERMISSIONS:
##
## Set and remove write permissions from a file
#
## change mode to read only
#alias -w chmod -w
#
## change mode to add write permission
#alias +w chmod u+w

## TAIL ALIAS:
##
#alias ptail 'set end=(`wc -l \!^`); set start; @ start = $end[1] - 9; \\
#sed -n $start,\$p \!^ ; unset start end'

## FIND DOUBLED WORDS:
##
#alias  ww      'deroff -w \!* | uniq -d'

## USING MULTIPLE .exrc FILES:
##
## aliases for vi -- switching between .exrc files and calling vi with
##                   a search
#
#setenv EXSTAT text        # INITIALIZATION FOR 'vi' ALIAS
#
#        # --- THESE ALIASES RESET THE .exrc FILE --- #
## SET 'vi' FOR 4-CHARACTER TABS/SHIFTS:
#alias 4vi 'cp ~/lib/vi/exrc4 ~/.exrc; setenv EXSTAT programming'
## SET 'vi' FOR 8-CHARACTER TABS/SHIFTS:
#alias 8vi 'cp ~/lib/vi/exrc8 ~/.exrc; setenv EXSTAT text'
## SET 'vi' FOR QUICK WORK WHEN SYSTEM IS SLOW (NO .exrc FILE):
#alias qvi 'rm ~/.exrc; setenv EXSTAT quick'
#
#        # --- THESE ARE THE vi ALIASES. ONE SETS THE vi MODE FIRST --- #
#alias vi 'echo "MODE: $EXSTAT"; /usr/ucb/vi \!*'
## CALL vi WITH A SEARCH:
#alias vs '8vi; vi +/\!*'

## ESCAPE SEQUENCES FOR VT102:
##
## VT102 AND COMPATIBLE TERMINAL CONTROL ESCAPE SEQUENCES
#
#set e = "`echo X | tr X '\033'`"        # ESCape character
#
#alias Clear 'echo -n "${e}[;H${e}[2J"'  # move to top left, clear screen
#
## ALTERNATE CHARACTER SETS.  YOU USUALLY WANT "NOG" TO CLEAR THESE
## WHEN YOUR TERMINAL GETS IN THIS MODE ACCIDENTALLY:
#
#alias NOG 'echo -n "${e}(B"'       #
...

read more »

 
 
 

1. csh: if-then-else-endif in csh alias?


: I am converting some Korn Shell scripts to Csh.

Leave them in ksh.  Especially if they work.

: The Korn Shell scripts have some simple shell functions that use
: if-then-else-fi control structures in them. Is there no way to do
: this with a Csh alias? I know that you can do plain one-line if
: constructs in a Csh alias, but the bug in the pudding comes when
: I try to do the then-else-endif.

That's because you can't do one-line if-then-else-endif constructs in
csh.  You just can't.  It's impossible.  Same goes for foreaches.

Don't write shell scripts in csh.  It's broken.  Really.  It should've
never gotten out in the first place.  There's a detailed FAQ.

--Dave

2. A bad but working solution for Red Hat 8.0(2.4.18-14) and aic-7902 (SE7501WV2)

3. adaptec aha2742-fuji-1gb

4. aliases, aliases, aliases...

5. arch/i386/kernel/setup.c references non-existant website

6. script alias problem - Re: apache alias and script alias problem

7. bad sectors in HD

8. csh: alias and nested quotes!!! :-(

9. Building an awk alias in (t)csh

10. ** Question for complex alias in csh ***

11. Aliases in Csh

12. csh aliases with block if statements