Sponsored Content
Full Discussion: Relative path not safe
Top Forums Shell Programming and Scripting Relative path not safe Post 302796633 by Scrutinizer on Saturday 20th of April 2013 04:43:00 AM
Old 04-20-2013
I suspect he is referring to $PWD which is the basis for your paths. So all your paths will be relative to $PWD, which is the path the caller of the script happens to be in when he calls the script. So indeed that location would be determined outside the script.

So you would either need to use a cd-command before that statement or use an absolute path instead. Or, if you need to use paths relative to the location of your script, you could perhaps use information from $0 as the basis...
 

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

getting full path from relative path

given a relative path, how do i convert it into a full one. i.e. if i am in /home/polypus and i am given foo/bar then to get a full path i can just concatinate it with pwd, but what if i am given "../mama" how do i programmatically convert: /home/polypus and ../mama into ... (4 Replies)
Discussion started by: polypus
4 Replies

3. 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

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

how to read the relative path

suppose i ahve a shell script Nsdnet.sh inside a directory /dialp/Release/bin another file nsdnet_file.csv is under the same directory. Now in the shell script i have call a java file, which reads the csvfile from the commandline. Now when i run the file as $ ./Nsdnet.sh ./nsdnet_file.csv then... (5 Replies)
Discussion started by: priyanka3006
5 Replies

6. 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

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. 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

9. UNIX for Dummies Questions & Answers

Help with cp command using relative path?

I have a lab I am doing for a Linux Operating class. The question I am stumped on is "For the following questions, only use the cp command to copy files. You should currently be inside your lab07 directory. Create a subdirectory inside this directory called ones and copy (working ... (1 Reply)
Discussion started by: CodyMongrel
1 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
fileutil_traverse(n)						  file utilities					      fileutil_traverse(n)

__________________________________________________________________________________________________________________________________________________

NAME
fileutil_traverse - Iterative directory traversal SYNOPSIS
package require Tcl 8.3 package require fileutil::traverse ?0.4.1? package require fileutil package require control ::fileutil::traverse ?objectName? path ?option value...? $traverser command ?arg arg ...? $traverser files $traverser foreach filevar script $traverser next filevar _________________________________________________________________ DESCRIPTION
This package provides objects for the programmable traversal of directory hierarchies. The main command exported by the package is: ::fileutil::traverse ?objectName? path ?option value...? The command creates a new traversal object with an associated global Tcl command whose name is objectName. This command may be used to invoke various operations on the traverser. If the string %AUTO% is used as the objectName then a unique name will be generated by the package itself. Regarding the recognized options see section OPTIONS. Note that all these options can be set only during the creation of the traver- sal object. Changing them later is not possible and causes errors to be thrown if attempted. The object command has the following general form: $traverser command ?arg arg ...? Command and its arguments determine the exact behavior of the object. The following commands are possible for traversal objects: $traverser files This method is the most highlevel one provided by traversal objects. When invoked it returns a list containing the names of all files and directories matching the current configuration of the traverser. $traverser foreach filevar script The highlevel files method (see above) is based on this mid-level method. When invoked it finds all files and directories matching per the current configuration and executes the script for each path. The current path under consideration is stored in the variable named by filevar. Both variable and script live / are executed in the context of the caller of the method. In the method files the script simply saves the found paths into the list to return. $traverser next filevar This is the lowest possible interface to the traverser, the core all higher methods are built on. When invoked it returns a boolean value indicating whether it found a path matching the current configuration (True), or not (False). If a path was found it is stored into the variable named by filevar, in the context of the caller. The foreach method simply calls this method in a loop until it returned False. This method is exposed so that we are also able to incrementally traverse a directory hierarchy in an event-based manner. OPTIONS
-prefilter command_prefix This callback is executed for directories. Its result determines if the traverser recurses into the directory or not. The default is to always recurse into all directories. The callback is invoked with a single argument, the absolute path of the directory, and has to return a boolean value, True when the directory passes the filter, and False if not. -filter command_prefix This callback is executed for all paths. Its result determines if the current path is a valid result, and returned by next. The default is to accept all paths as valid. The callback is invoked with a single argument, the absolute path to check, and has to return a boolean value, True when the path passes the filter, and False if not. -errorcmd command_prefix This callback is executed for all paths the traverser has trouble with. Like being unable to change into them, get their status, etc. The default is to ignore any such problems. The callback is invoked with a two arguments, the absolute path for which the error occured, and the error message. Errors thrown by the filter callbacks are handled through this callback too. Errors thrown by the error callback itself are not caught and ignored, but allowed to pass to the caller, i.e. however invoked the next. Any other results from the callback are ignored. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category fileutil of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
directory traversal, traversal CATEGORY
Programming tools fileutil 0.4.1 fileutil_traverse(n)
All times are GMT -4. The time now is 01:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy