summaryrefslogtreecommitdiff
path: root/EXAMPLES
blob: 93250abedf72292f57206d334a6e36d3663fd6ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
>#! /bin/bash
>umask 022
>export PATH=".:~/bin:/bin:/usr/bin"
>export HOME=`(cd ~; pwd)`
>alias which="$HOME/c/which/which"

>touch cat; chmod 755 cat; pwd
/home/carlo/c/which
>alias

>which
Usage: which [options] [--] programname [...]
Options: --version, -[vV] Print version and exit successfully.
         --help,          Print this help and exit successfully.
         --skip-dot       Skip directories in PATH that start with a dot.
         --skip-tilde     Skip directories in PATH that start with a tilde.
         --show-dot       Don't expand a dot to current directory in output.
         --show-tilde     Output a tilde for HOME directory for non-root.
         --tty-only       Stop processing options on the right if not on tty.
         --all, -a        Print all matches in PATH, not just the first
         --read-alias, -i Read list of aliases from stdin.
         --skip-alias     Ignore option --read-alias; don't read stdin.
         --read-functions Read shell functions from stdin.
         --skip-functions Ignore option --read-functions; don't read stdin.

>which --version
GNU which v2.17, Copyright (C) 1999 - 2007 Carlo Wood.
GNU which comes with ABSOLUTELY NO WARRANTY;
This program is free software; your freedom to use, change
and distribute this program is protected by the GPL.

>which -- --version
which: no --version in (.:~/bin:/bin:/usr/bin)

>which cat
/home/carlo/c/which/cat

>which --show-tilde cat
~/c/which/cat

>which --show-dot cat
./cat

>which --show-tilde --show-dot cat
./cat

>which --skip-dot cat
/bin/cat

>(cd /bin; which cat)
/bin/cat

>(cd /bin; which --show-dot cat)
./cat

>(cd /bin; PATH=".:/bin:/usr/bin" which --show-dot cat)
./cat

>(cd /bin; PATH="/bin:.:/usr/bin" which --show-dot cat)
/bin/cat

>(cd /bin; PATH=".:/bin:/usr/bin" which --skip-dot --show-dot cat)
/bin/cat

>which ls
/bin/ls

>which xxx
which: no xxx in (.:~/bin:/bin:/usr/bin)

>which ./ls
which: no ls in (.)

>(cd /; which bin/ls)
/bin/ls

>(cd /; which --show-dot bin/ls)
./bin/ls

>(cd /; which --show-dot /bin/ls)
/bin/ls

>(cd /; which --show-dot bin/xxx)
which: no xxx in (./bin)

>(cd /; which --show-dot /bin/xxx)
which: no xxx in (/bin)

>which --all cat
/home/carlo/c/which/cat
/bin/cat

>touch xxx
>which ./xxx
which: no xxx in (.)

>chmod 711 xxx
>which ./xxx
/home/carlo/c/which/xxx

>chmod 655 cat
>which cat
/bin/cat

>su
>chown root cat
>exit
>which cat
/home/carlo/c/which/cat

>su
>chmod 545 cat
>exit
>which cat
/bin/cat

>su
>chgrp bin cat
>exit
>which cat
/home/carlo/c/which/cat

>su
>chmod 541 cat
>exit
>which cat
/home/carlo/c/which/cat
>su
>rm -f cat

>chown root xxx
>exit
>which ./xxx
/home/carlo/c/which/xxx

>su
>chmod 700 xxx
>exit
>which ./xxx
which: no xxx in (.)

>id
uid=1000(carlo) gid=1000(carlo) groups=20(dialout),24(cdrom),25(floppy),29(audio),44(video),46(plugdev),106(netdev),109(powerdev),115(kvm),1000(carlo)
>ls -l xxx
-rwx------ 1 root carlo 0 2007-10-09 17:26 xxx
>su
>chmod 750 xxx
>chgrp carlo xxx
>exit
>which ./xxx
/home/carlo/c/which/xxx

>su
>chgrp bin xxx
>exit
>which ./xxx
which: no xxx in (.)

>alias which='alias | which --tty-only --read-alias --show-tilde --show-dot'
>alias test1='test1'
>alias test2='echo "test2" | cat | sort'
>alias test3='  echo "test2"|cat&sort'
>alias test4='	ls &&sort ||/usr/bin/which || exit'

>which which
alias which='alias | which --tty-only --read-alias --show-tilde --show-dot'
	~/c/which/which
>which test1
alias test1='test1'
>which test2
alias test2='echo test2 | cat | sort'
	/bin/echo
	/bin/cat
	/usr/bin/sort
>which test3
alias test3='  echo test2|cat&sort'
	/bin/echo
	/bin/cat
	/usr/bin/sort
>which test4
alias test4='	ls &&sort ||/usr/bin/which || exit'
	/bin/ls
	/usr/bin/sort
	/usr/bin/which