Custom directory path variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Custom directory path variable
# 8  
Old 10-08-2010
What do you think would be the simplest test?
Never thought about using ls?
If it displays: "No such file or directory " then you dont cd...
# 9  
Old 10-08-2010
Quote:
Originally Posted by vbe
What do you think would be the simplest test?
Never thought about using ls?
If it displays: "No such file or directory " then you dont cd...
I'm not looking for a way to find a directory, I'm looking for a way to get the full path based on a shell script's working directory and a directory argument sent to the script, into a variable.
# 10  
Old 10-08-2010
The only option I see is testing the user input to the shell to see what you want to do from there. A case/esac structure might work well in this instance. Perhaps coupled with "dirname"

Something like


Code:
 
USERIN=$1 

case "$(dirname $USERIN)" in
  /) echo fully qualified;;
  .) echo relative to current directory;;
  ..) echo relative to parent directory;;
  ../..) echo relative to parent/parent directory;;
...  # < --- replace this
esac

You need to replace the ellipses with one test for each level it can go beyond the script's parent/parent directory back to root.

Obviously you replace the echo statements with code that actually works for you.

dirname seems to know that if you give the name "somewhere" or the name "./somewhere" it will translate that to a single dot "." so that reduces the amount of
tests by one.

And of course after I post that, I realize there's still a host of things that wont work correctly, depending upon input like (../somewhere/else) but maybe this will get you started somewhat? :-)

Last edited by rwuerth; 10-08-2010 at 12:23 PM..
# 11  
Old 10-08-2010
Looking more and more like homework, and no collaboration ( you havent shown so far anything of your work without paying attention to what is said there...)
So until you can prove it is not, this thread is considered as homework by someone unwilling to learn and closed

---------- Post updated at 18:06 ---------- Previous update was at 18:05 ----------

Sorry rwuerth...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies

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

3. Shell Programming and Scripting

Variable of Path directory is not parsing in awk

Hi All, i had to split one files into 10 equally. For that i have coded below awk. OUTPUT_FILE=/home/sit/path/Files/file_EXPORT.lst DIR_NM=`dirname ${OUTPUT_FILE}` awk -v CURR_DATE="$(date +'%d-%m-%Y-%H-%M')" -v pth=$DIR_NM '{print >> pth/"tgt_file_name"CURR_DATE"_"NR%10 }' ${OUTPUT_FILE} ... (7 Replies)
Discussion started by: looney
7 Replies

4. UNIX for Advanced & Expert Users

How can i assign directory path to a variable in perl?

Hai how can I assign directory path to a variable in perl Thanks&Regards kiran (3 Replies)
Discussion started by: kiran425
3 Replies

5. UNIX for Dummies Questions & Answers

How can i assign directory path to a variable in perl?

Hai how can I assign directory path to a variable in perl Thanks&Regards kiran (2 Replies)
Discussion started by: kiran425
2 Replies

6. UNIX for Dummies Questions & Answers

Make install in custom path

I would like to install a binary from source on a custom path, say /usr/local/myapps. There is no --prefix option in ./configure How can I "make install" at custom path. I tried this. No --prefix root@server # ./configure --help | grep prefix root@server # Make install ... (3 Replies)
Discussion started by: anil510
3 Replies

7. UNIX for Dummies Questions & Answers

Find command fails when a space is in the directory path variable

I have a script like this running under OS X 10.8. The problem arises when the find command encounters a space in the path name. I need the "dir" variable as I'll be extending the script to more general use. #!/bin/bash CFS=$IFS IFS=$(echo) set dir = "/Users/apta/Library/Mail\... (3 Replies)
Discussion started by: apta
3 Replies

8. Shell Programming and Scripting

zlib.h in custom path

I am trying to configure gpac. I get the error as follows. # ./configure error: zlib not found on system or in local libs I have installed zlib on custom path /usr/local/myapps. I know the above error occurs when devel package or .h file is not present. Its present on the server. # ll... (7 Replies)
Discussion started by: anilcliff
7 Replies

9. Shell Programming and Scripting

Variable directory name in path

I need to write a login script for multiple computers, however, one of the directories in question will have a different name from computer to computer. ~/Library/Application\ Support/Firefox/Profiles/<unique filename>.default/myfile For the directory named <unique filename>.default , I... (2 Replies)
Discussion started by: glev2005
2 Replies

10. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies
Login or Register to Ask a Question