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

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


#!/bin/rc
# which file will this command envoke

rfork e

if (~ $#* 0){
	echo 'usage: which file...'
	exit 'usage'
}

for(dir in $path){
	if(~ $dir /bin){
		{ for (nsdir in `{ns | awk '$NF == "/bin" {print dir, $(NF -1)}'}){
			if (test -f $nsdir/$1)
				echo $nsdir/$1
		} } | tail -r
	}
	if(! ~ $dir /bin){
		if (test -f $dir/$1)
			echo $dir/$1
	}
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].