Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've placed a file in the location

/tmp/parent_dir/child_dir/file_1

The script is placed in the location

/usr/local/bin/file_load/load_data

From this location (/usr/local/bin/file_load/load_data), how can I access the file (file_1) which is placed in another location (/tmp/parent_dir/child_dir/file_1) from within the script?

share|improve this question
    
You do not actually ask any question. Try to state more clearly what exactly is your issue, and give a code sample if it applies. –  Daniel Andersson Jun 20 '12 at 13:27

1 Answer 1

Do you want the shell script to receive the path of the file on the command line? Something like this would help:

#!/bin/bash
file=$1
cat $file

You can then call the script like this:

 /usr/local/bin/file_load/load_data /tmp/parent_dir/child_dir/file_1

which will output the file.

share|improve this answer
    
Giridharan: I'm running a script which needs to access files placed in a location other than the location of the corresponding script. To be precise, the files are in one location while the script that access the files are in another location. My question is how to access those files from within the script? When I give the absolute path in the script to refer to the location ('/tmp/parent_dir/child_dir/file_1'), it throws an error saying '/parent_dir/tmp: No such file or directory' –  Giridharan Jun 20 '12 at 13:57
    
Can you show us the part of the script where you use the path to the file? The error message doesn't make much sense (parent_dir and tmp have switched positions?). –  Kenneth Hoste Jun 20 '12 at 14:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.