Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / examples / functions / csh-compat
1 # C-shell compatabilty package.
2 # setenv VAR VALUE
3 function setenv ()
4 {
5   export $1="$2"
6 }
7
8 function unsetenv ()
9 {
10   unset $1
11 }
12
13 # Can't write foreach yet.  Need pattern matching, and a few extras.
14 function foreach () {
15 echo 'Can'\''t do `foreach'\'' yet.  Type "help for".'
16 }
17
18 # Make this work like csh's.  Special case "term" and "path".
19 #set () {
20 #}
21
22 chdir ()
23 {
24   builtin cd "$@"
25 }
26
27 # alias - convert csh alias commands to bash functions
28 # from Mohit Aron <aron@cs.rice.edu>
29 # posted to usenet as <4i5p17$bnu@larry.rice.edu>
30 function alias ()
31 {
32         if [ "x$2" = "x" ] 
33         then
34                 declare -f $1
35         else
36                 echo $2 | egrep -s '(\!|#)' 2>/dev/null
37                 if [ $? -eq 0 ]
38                 then
39                         comm=$(echo $2 | sed  's/\\!\*/\"$\@\"/g
40                                                s/\\!:\([1-9]\)/\"$\1\"/g
41                                                s/#/\\#/g')
42                 else
43                         comm="$2 \"\$@\""
44                 fi
45                 eval function $1 \(\) "{" command "$comm"  "; }"
46         fi
47 }