Finding path of a running script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding path of a running script
# 1  
Old 08-19-2008
Question Finding path of a running script

Hi,
I just want to know any code by which i can get the path of the script which i am running. This is required to store the output in the same directory from where the script is running. pwd fails if I give absolute path of script from some other directory.
Thanks in advance
Puneet
# 2  
Old 08-19-2008
try ps -ef|grep scriptname... or something like this..
# 3  
Old 08-19-2008
Code:
 /usr/ucb/ps -wwaxe processid | tr " " "\n" | grep PWD

should work or:

Code:
/usr/ucb/ps -wwaxe 54458 | sed 's/.* \(PWD=[^ ]*\) .*/\1/'

# 4  
Old 08-19-2008
You can use realpath to retrieve the canonicalized absolute pathname of your shell script.
With this information you can easily figure out the current working directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Finding the path to an executable , installed package

Hi all, Recently i wanted to see if i have openssl installed in my system (solaris 10), so i do this (not sure if this is the right way to do this) pkginfo -i | grep -i "ssl" system SUNWopenssl-commands OpenSSL Commands (Usr) system SUNWopenssl-include ... (3 Replies)
Discussion started by: javanoob
3 Replies

2. Shell Programming and Scripting

Finding a script/program on $PATH

I am trying to put together a script to find a requested script or program on the user's search path. Am trying to replace the colons separating the parts of a path with a newline to let xargs pass the directories to a list command, but I haven't gotten that far. This is my progress: echo... (7 Replies)
Discussion started by: wbport
7 Replies

3. Shell Programming and Scripting

Finding which is Running number

Hi All, I have a list of data in the listing file and I run row by row to process the record, but how to identify what is the current process line number ? Thanks. (2 Replies)
Discussion started by: ckwan
2 Replies

4. Programming

Finding the path of the C program

Hi All, I have a c program called findPath.c in a path /home/harsh/c-Programs/. How can i find the path where the program is stored at runtime?? I have given the following #include<stdio.h> int main() { system("dirname $0"); return 0; } This is resulting in the output as . <single dot... (6 Replies)
Discussion started by: sreeharshasn
6 Replies

5. UNIX for Dummies Questions & Answers

running script without a path

can someone tell me how could I run a script in an environment that does not include a path? like the environment provided by cron? (1 Reply)
Discussion started by: ikeQ
1 Replies

6. Shell Programming and Scripting

path of the running script

Hi there, After reading a couple posts on the subject, I came up with the compilation of all advice (that are supposed to work on any situation) and wrote the following script. But tell me something... Is it that crazy that there's no other way to get the same solution!!! #!/bin/bash... (27 Replies)
Discussion started by: chebarbudo
27 Replies

7. UNIX for Dummies Questions & Answers

finding a file in its path

I have a file that has multiple entries within the Unix system. Korn shell scripts are calling this file (also a ksh) with a . in front of it, and I'm trying to determine which file it is using based on the $PATH by finding where it is located first. Any suggestion on how to go about this?... (2 Replies)
Discussion started by: gavineq
2 Replies

8. Shell Programming and Scripting

Finding relative path of a file

I have to relatively get the path of a file to use it in the script. The directory structure is /export/opt/XTools/ and under this there are several version directories - 1.0_A0, 1.0_A1, 1.0_A2 etc.,. The actual file is under these directories: installscript.sh My script should pickup the... (4 Replies)
Discussion started by: chiru_h
4 Replies

9. IP Networking

finding the java path in AIX

How to retrieve the path of Java bin directory in AIX (or any unix OS)?? Actually my problem is, I have a jar file called App.jar. I want to execute it by calling the javaw executable. My command is "/usr/java130/javaw -jar App.jar". I've written this command into a shell script. Now,... (2 Replies)
Discussion started by: fermisoft
2 Replies

10. UNIX for Dummies Questions & Answers

Finding current working dir path

Hi Folks, In a Unix (ksh) script, is there a way to determine the current working directory path of another logged-in user? Of course, I can use "pwd" to find my own path. But, how do I find it for another active user? Thanks for any input you can provide. LY (6 Replies)
Discussion started by: liteyear18
6 Replies
Login or Register to Ask a Question