Can a shell script easily find itself?

2013-07-21 Thread Michael
I feel silly for asking this. But I just realized I don't try this very often. Is there a way for a shell script to find itself? Or more precisely, the directory it is in? I am trying to run a program that wants an ini file specified on the command line; but it defaults to the assumption of

Re: Can a shell script easily find itself?

2013-07-21 Thread John Musbach
Use the command pwd. On Sun, Jul 21, 2013 at 4:16 PM, Michael keybou...@gmail.com wrote: I feel silly for asking this. But I just realized I don't try this very often. Is there a way for a shell script to find itself? Or more precisely, the directory it is in? I am trying to run a

Re: Can a shell script easily find itself?

2013-07-21 Thread Michael
Use the command pwd. Nope. That tells me where the user is, not where the shell script is. On Sun, Jul 21, 2013 at 4:16 PM, Michael keybou...@gmail.com wrote: I feel silly for asking this. But I just realized I don't try this very often. Is there a way for a shell script to find itself?

Re: Can a shell script easily find itself?

2013-07-21 Thread Robert Love
to expand on this answer you can use ` to save the result of the command. Try this HERE=`pwd` echo $HERE so now the current path is in a variable for your script to use. On Jul 21, 2013, at 3:46 PM, John Musbach johnmusba...@gmail.com wrote: Use the command pwd. On Sun, Jul 21, 2013

Re: Can a shell script easily find itself?

2013-07-21 Thread John Musbach
On Sun, Jul 21, 2013 at 4:54 PM, Michael keybou...@gmail.com wrote: Use the command pwd. Nope. That tells me where the user is, not where the shell script is. Are you sure? If you do say, SCRIPT_DIR=`pwd` echo $SCRIPT_DIR the echo should return the directory the script ran in. On Sun,

Re: Can a shell script easily find itself?

2013-07-21 Thread Robert Love
Hm, here is a discussion on Stack Overflow of your question. http://online.wsj.com/article/SB10001424127887324348504578606493979321554.html On Jul 21, 2013, at 4:23 PM, Michael keybou...@gmail.com wrote: Use the command pwd. Nope. That tells me where the user is, not where the shell script

Re: Can a shell script easily find itself?

2013-07-21 Thread Hacker Scot
On Jul 21, 2013, at 1:57 PM, John Musbach johnmusba...@gmail.com wrote: On Sun, Jul 21, 2013 at 4:54 PM, Michael keybou...@gmail.com wrote: Use the command pwd. Nope. That tells me where the user is, not where the shell script is. Are you sure? If you do say, SCRIPT_DIR=`pwd`

Re: Can a shell script easily find itself?

2013-07-21 Thread Michael
Hm, here is a discussion on Stack Overflow of your question. http://online.wsj.com/article/SB10001424127887324348504578606493979321554.html I think that's the wrong paste :-). But in response to that article: Our constitution puts the U.S. Supreme court at the top; international courts

Re: Can a shell script easily find itself?

2013-07-21 Thread Michael
Hm, here is a discussion on Stack Overflow of your question. http://online.wsj.com/article/SB10001424127887324348504578606493979321554.html I think that's the wrong paste :-). Correct one:

Re: Can a shell script easily find itself?

2013-07-21 Thread LuKreme
On 21 Jul 2013, at 14:16 , Michael keybou...@gmail.com wrote: I feel silly for asking this. But I just realized I don't try this very often. Is there a way for a shell script to find itself? Or more precisely, the directory it is in? Yes, but it depends on the shell. DIR=$( cd $( dirname

Re: Can a shell script easily find itself?

2013-07-21 Thread Macs R We
There wasn't last time I tried this about 20 years ago. :-( The reason is the architecture of the UNIX file system, where file contents actually reside in inodes, and directory entries are really only links to inodes. For example, you create a script. Now you put a hard link to that script