Tuesday, July 28, 2009

Unix filepath issue?

Another Unix question thanks to my new course.





"I have developed a set of scripts that use the absolute pathname /afs/asu.edu/users/a/t/r/atrow/www, the SysAdmin has now informed me that my new home directory is going to be /afs/asu.edu/home/a/t/r/atrow. How should I have written my scripts so that I don't need to go back and rewrite them all?"





/afs/asu.edu/users/a/t/r/atrow/www


/afs/asu.edu/home/a/t/r/atrow





The "home" and "user" portion is clearly what needs to be revised unless there is a way to create a soft link. I could create a soft link to /afs/asu.edu/users/a/t/r/atrow/www when the user enters /afs/asu.edu/home/a/t/r/atrow. I believe this is the correct answer, what do you guys think?

Unix filepath issue?
I can think of two possible solutions. For one, '~/' is a Unix shortcut for referring to your home directory, so '~/' should be the same thing as '/afs/asu.edu/users/a/t/r/atrow/'. Try it by typing:





cd ~/


pwd





And see if you are in the correct directory. If so, then you can just start your paths with '~/' and leave the '/afs/asu.edu/users/a/t/r/atrow/' off.





Another option that is probably available is the $HOME environment variable. Try running:





echo $HOME





And see if it prints out your home directory. If it does, then in your scripts you can create paths by referring to them like "${HOME}/www" instead of typing out the actual directory.





Either way, if you home directory changes then '~/' and $HOME should follow suit.





Also, you could just play around with relative paths instead of absolute paths if you wanted... but that's a whole separate Q%26amp;A.


No comments:

Post a Comment