Plan 9 from Bell Labs’s /usr/web/sources/contrib/quanstro/which

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc
rfork e

fn order{
	ns | awk '
	$NF == "'^$1^'" {
		if(n == 0 || NF == 3) {
			n++;
			i = 0;
			min=-1;
			max=1
		}else if($2 == "-b")
			i=min--;
		else
			i=max++;
		t[i] = $(NF-1);
	} 

	END{
		for(i=min+1; i<max; i++)
			print t[i];
	}'
}

fn u{
	awk '
	{
		t[$1] = 1;
	}
	END{
		for(i in t)
			print i
	}'
}

for(i)
	{for(j in $path){
		p=$j
		if(~ $p .)
			p = `{pwd}
		for(k in `{order $p})
			if(test -f $k/$i)
				echo $k/$i
	}}|u

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.