a little modification
Quote:
a little modifiation :) Code:
source="./tmp/myfile" |
Quote:
|
Quote:
ta0kira has it right: to return the absolute path of a filename that is originally given with a relative path: for example you are at a bash prompt in /dir1/dir2/dir3/dir4 and the file is /dir1/dir2/file1 ABSOLUTE_DIR=$(dirname $(readlink -f ../../dir2/file1)) |
A solution I found elsewhere...
|
Another solution is to use the external pwd command instead of the bash builtin. In the following illustration /home/c/Templates is a symlink to /home/c/d/Templates
Code:
c@CW9:~$ ls -l Templates |
I didn't know readlink was nonstandard. Thanks to the suggestions, this is what I've come up with.
Code:
#!/bin/bash |
I like this better:
Code:
#!/bin/bash |
I made another change. In the previous function I posted, it has to be called three times if the absolute path, absolute path with filename, and base filename are required. That can slow things down. This method may be slightly more memory intensive, but speeds up the process.
Code:
function gfp_info() { |
It could go a little faster if:
pwd does not return the absolute path if the path was reached via a symlink in which case pwd -P is needed: Code:
c@CW8:~$ cd /tmp |
Quote:
|
I've made the changes to my script, with some exceptions.
cd "-" &>/dev/null And when I was using rmw on a file in my present working directory, RP=${FILE%/*} would kick out an error. (No slash to find) Thanks for the suggestions, catkin. Good stuff. |
Quote:
Code:
c@CW8:/tmp$ FILE=foo |
I was wrong about the slash, but the code you suggested assigns the basename, whereas I want everything except for the basename. Since I'm not good at explaining, allow me to illustrate:
Code:
# extracts the directory component of the full path FILE: temp /home/andy/bin/rmw: line 451: cd: temp: Not a directory DC: "temp" pwd: - "/home/andy/Documents" `temp' -> `/home/andy/.Waste/files/temp.2011-01-26h13m11s43' --- Code:
# extracts the directory component of the full path FILE: temp DC: "" pwd: - "/home/andy/Documents" `temp' -> `/home/andy/.Waste/files/temp.2011-01-26h13m14s23' I've added an if clause around cd $DC Code:
if [ $DC ]; then |
For the basename: basename=${fullpath##*/}. It looks like this at the command prompt:
Code:
c@CW8:/tmp$ fullpath=/etc/rsyncd.conf |
Code:
function gfp_info() { |
All times are GMT -5. The time now is 06:30 AM. |