Imported from ../bash-2.01.tar.gz.
[platform/upstream/bash.git] / examples / functions / xalias.bash
1 # xalias - convert csh alias commands to bash functions
2 # from Mohit Aron <aron@cs.rice.edu>
3 # posted to usenet as <4i5p17$bnu@larry.rice.edu>
4 function xalias ()
5 {
6         if [ "x$2" = "x" ] 
7         then
8                 declare -f $1
9         else
10                 echo $2 | egrep -q '(\!|#)'
11                 if [ $? -eq 0 ]
12                 then
13                         comm=$(echo $2 | sed  's/\\!\*/\"$\@\"/g
14                                                s/\\!:\([1-9]\)/\"$\1\"/g
15                                                s/#/\\#/g')
16                 else
17                         comm="$2 \"\$@\""
18                 fi
19                 eval function $1 \(\) "{" command "$comm"  "; }"
20         fi
21 }