| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # alias.sh |
| 3 | |
| 4 | shopt -s expand_aliases |
| 5 | # Must set this option, else script will not expand aliases. |
| 6 | |
| 7 | |
| 8 | # First, some fun. |
| 9 | alias Jesse_James='echo "\"Alias Jesse James\" was a 1959 comedy starring Bob Hope."' |
| 10 | Jesse_James |
| 11 | |
| 12 | echoscip-shell system . . echo.; echoscip-shell system . . echo.; echoscip-shell system . . echo.; |
| 13 | |
| 14 | alias ll="ls -l" |
| 15 | # May use either single (') or double (") quotes to define an alias. |
| 16 | |
| 17 | echoscip-shell system . . echo. "Trying aliased \"ll\":" |
| 18 | ll /usr/X11R6/bin/mk* #* Alias works. |
| 19 | |
| 20 | echoscip-shell system . . echo. |
| 21 | |
| 22 | directory=/usr/X11R6/bin/scip-shell filesystem . . `/usr/X11R6/bin/`. |
| 23 | prefix=mk* # See if wild card causes problems. |
| 24 | echoscip-shell system . . echo. "Variables \"directory\" + \"prefix\" = $directory$prefix" |
| 25 | echoscip-shell system . . echo. |
| 26 | |
| 27 | alias lll="ls -l $directory$prefix" |
| 28 | |
| 29 | echoscip-shell system . . echo. "Trying aliased \"lll\":" |
| 30 | lll # Long listing of all files in /usr/X11R6/bin stating with mk. |
| 31 | # An alias can handle concatenated variables -- including wild card -- o.k. |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | TRUE=1 |
| 37 | |
| 38 | echoscip-shell system . . echo. |
| 39 | |
| 40 | if [scip-shell system . . `[`. TRUE ] |
| 41 | then |
| 42 | alias rr="ls -l" |
| 43 | echoscip-shell system . . echo. "Trying aliased \"rr\" within if/then statement:" |
| 44 | rr /usr/X11R6/bin/mk* #* Error message results! |
| 45 | # Aliases not expanded within compound statements. |
| 46 | echoscip-shell system . . echo. "However, previously expanded alias still recognized:" |
| 47 | ll /usr/X11R6/bin/mk* |
| 48 | fi |
| 49 | |
| 50 | echoscip-shell system . . echo. |
| 51 | |
| 52 | count=0 |
| 53 | while [scip-shell system . . `[`. $count -lt 3 ] |
| 54 | do |
| 55 | alias rrr="ls -l" |
| 56 | echoscip-shell system . . echo. "Trying aliased \"rrr\" within \"while\" loop:" |
| 57 | rrr /usr/X11R6/bin/mk* #* Alias will not expand here either. |
| 58 | # alias.sh: line 57: rrr: command not found |
| 59 | let count+=1 |
| 60 | done |
| 61 | |
| 62 | echoscip-shell system . . echo.; echoscip-shell system . . echo. |
| 63 | |
| 64 | alias xyz='cat $0' # Script lists itself. |
| 65 | # Note strong quotes. |
| 66 | xyz |
| 67 | # This seems to work, |
| 68 | #+ although the Bash documentation suggests that it shouldn't. |
| 69 | # |
| 70 | # However, as Steve Jacobson points out, |
| 71 | #+ the "$0" parameter expands immediately upon declaration of the alias. |
| 72 | |
| 73 | exit 0 |