Sponsored Content
Top Forums Shell Programming and Scripting Determining absolute PATH within KSH script Post 22967 by Perderabo on Thursday 13th of June 2002 02:55:40 PM
Old 06-13-2002
If it has to work all the time, it's impossible. There is no hope with something like:
cat /tmp/myscript | ksh
There is also no hope when sourcing the file.

$0 should work in most other cases, in fact, I can't think of another case where it fails. If $0 is a relative path, you may want to tranform it into a absolute path.

It is low-tech, but you could put a line:
MYPATH=/tmp/myscript
in the script. If the script is running as root, the script can invoke fuser on MYPATH and verify that the current process at least has the file open.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

vi - replacing a relative path with absolute path in a file

Hi, I have a file with about 60 lines of path: app-defaults/boxXYZ....... I want to change this to /my/path/goes/here/app-defaults/boxXYZ, but of course vi doesn't like the regualr :s/old/new/ command. Is there any other quick way to do this? Thanks ;) (2 Replies)
Discussion started by: Yinzer955i
2 Replies

2. Shell Programming and Scripting

Determining directory path

Hello, I have a script where I get the full directory path of the script being executed: BASE=$0 echo "BASE:" $BASE The output looks like this: BASE: /webapps/appsdev/ACURA/rlz/oses3.sh I'd like to truncate the shell name, leaving just the directory path. The directory path can be... (2 Replies)
Discussion started by: cwalsek
2 Replies

3. UNIX for Dummies Questions & Answers

absolute path

is cd ~ considered an absolute path? (2 Replies)
Discussion started by: Kirichiko
2 Replies

4. UNIX for Dummies Questions & Answers

Help with absolute path and relative path

I'm having problems accessing the Knoppix software on my current computer and the replacement CD I ordered hasn't arrived yet. I have a guess at what the answer would be for this question but I am not sure as I cannot test it with the software. I have to create a directory called class, and... (1 Reply)
Discussion started by: mzero
1 Replies

5. Shell Programming and Scripting

absolute path for a script ran with relative path

I have a script in which i want to print absolute path of the same script irrespective of path from where i run script. I am using test.sh: echo "pwd : `pwd`" echo "script name: $0" echo "dirname: `dirname $0`" when i run script from /my/test/dir/struct as ../test.sh the output i... (10 Replies)
Discussion started by: rss67
10 Replies

6. Shell Programming and Scripting

Determining whether given string is path or not

I have an issue while determing whether given string is unix path or not There is a text file which is normally a report in that at some place we have unix path as shown below /opt/smart/dev/eur/sources/sqr and not unix path as shown below Threshold Year/Month/Ref/ActLine/OUC Is there... (3 Replies)
Discussion started by: lalitpct
3 Replies

7. Shell Programming and Scripting

How to change Absolute path to Relative path

Hello, I have a doubt:- --------------------- Current script:- ################################################################################################ prefix=user@my-server: find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do ( cd "$path" || exit $?... (4 Replies)
Discussion started by: sahil_jammu
4 Replies

8. Shell Programming and Scripting

Automatically determining directory path for scripts and programs

I have some C++ code in the following directory structure /home/chrisd/tatsh/trunk/hstmy/ ├── baseLib ├── bin │ ├── awk │ ├── bash │ ├── diag │ ├── ksh │ │ └── TAG201011 │ ├── old │ ├── perl │ ├── prog │ ├── py │ └── tcsh ├── docs ├── fortran ├── others... (0 Replies)
Discussion started by: kristinu
0 Replies

9. UNIX for Dummies Questions & Answers

How to convert relative path to absolute path?

Hello Everyone, I want to convert Relative Path - /home/stevin/data/APP_SERVICE/../datafile.txt to Absolute Path - /home/stevin/data/datafile.txt Is there a built-in tool in Unix to do this or any good ideas as to how can I implement this. -Steve (5 Replies)
Discussion started by: qwarentine
5 Replies

10. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies
pathconv(1F)							   FMLI Commands						      pathconv(1F)

NAME
pathconv - search FMLI criteria for filename SYNOPSIS
pathconv [-f] [-v alias] pathconv [-t] [-l] [-nnum] [-v string] DESCRIPTION
The pathconv function converts an alias to its pathname. By default, it takes the alias as a string from the standard input. OPTIONS
-f If -f is specified, the full path will be returned (this is the default). -t If -t is specified, pathconv will truncate a pathname specified in string in a format suitable for display as a frame title. This format is a shortened version of the full pathname, created by deleting components of the path from the middle of the string until it is under DISPLAYW -- 6 characters in length, and then inserting ellipses ( ... ) between the remaining pieces. Ellipses are also used to show truncation at the ends of the strings if necessary, unless the -l option is given. -l If -l is specified, < and > will be used instead of ellipses ( ... ) to indicate truncation at the ends of the string generated by the -t option. Using -l allows display of the longest possible string while still notifying users it has been truncated. -nnum If -n is specified, num is the maximum length of the string (in characters) generated by the -t option. The argument num can be any integer from 1 to 255. -valias |string If the -v option is used, then alias or string can be specified when pathconv is called. The argument alias must be an alias defined in the alias_file named when fmli was invoked. The argument string can only be used with the -t option and must be a pathname. EXAMPLES
Example 1 A sample that uses pathconv to construct the menu title. It searches for MYPATH in the alias_file named when fmli command. Here is a menu descriptor that uses pathconv to construct the menu title. It searches for MYPATH in the alias_file named when fmli was invoked: menu=`pathconv -v MYPATH/ls` . . . where there is a line in alias_file that defines MYPATH . For example, MYPATH=$HOME/bin:/usr/bin. Here is a menu descriptor that takes alias from the standard input. menu=`echo MYPATH/ls | pathconv` . . . ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
fmli(1), attributes(5) SunOS 5.11 5 Jul 1990 pathconv(1F)
All times are GMT -4. The time now is 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy