Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.unix.questions Subject: Re: comp.unix.questions Keywords: shell script, directory Message-ID: <13768@smoke.BRL.MIL> Date: 7 Sep 90 16:18:39 GMT References: <1990Sep7.152354.9439@ecn.purdue.edu> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 20 In article <1990Sep7.152354.9439@ecn.purdue.edu> patkar@helium.ecn.purdue.edu (The Silent Dodo) writes: >I have a question about shell scripts. How can a shell script >(sh or csh) find out its own file name? Actually, I need to >know only the directory in which it resides. Here we go again. The shell script inode does not reside in any particular directory nor has it any particular inherent pathname. Several different directory entries can link to the same inode. Thus there is no unambiguous answer to your question. >My shell scripts need, say, some "sed" script files and it is >always nice to keep them in the same directory as the shell >script. So when I move the shell scripts to a different >directory or a different machine I have to make changes in the >pathname for the sed scripts. Is there a better way to do >this? Consider using the "here document" feature << to embed the subscripts in-line. Otherwise, you pretty much have to make at least one edit to each script that refers to other scripts when they have been moved.