🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1157

Re: Finding a script's location (was: Re: comp.unix.questions)

#1157
From: Jim Rogers
Date: Wed, 12 Sep 1990 17:39
33 lines
1080 bytes
The following script seems to meet all your requirements:
i.e. works when executable is:

	in an absolute path

	in a relative path

	in a path specified by the PATH avariable.



#! /bin/ksh

# This script displays the path name of the script itself
# from the command argument $0

name=$0
bname=`basename $name`
ipth=${name%$bname}
if [ "$bname" = "$name" ]
then
# Script somewhere on the path
	fpth=`whence $name`
	pth=${fpth%/$bname}
else
	cd $ipth
	pth=$PWD
fi
print "Path to $0 is $pth"


Jim Rogers
Hewlett Packard Company
Technical Details
Message-ID: <27620003@hp-lsd.COS.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!hpldola!hp-lsd!jimr
References: <9009101705.AA29830@mindcrf.mindcraft.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!hpldola!hp-lsd!jimr
From: jimr@hp-lsd.COS.HP.COM (Jim Rogers)
Newsgroups: comp.unix.shell
Subject: Re: Finding a script's location (was: Re: comp.unix.questions)
Message-ID: <27620003@hp-lsd.COS.HP.COM>
Date: 12 Sep 90 17:39:54 GMT
References: <9009101705.AA29830@mindcrf.mindcraft.com>
Organization: HP Logic Systems Division - ColoSpgs, CO
Lines: 33