Blame view

egs/wsj/s5/utils/make_absolute.sh 629 Bytes
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #!/bin/bash
  
  # This script replaces the command readlink -f (which is not portable).
  # It turns a pathname into an absolute pathname, including following soft links.
  target_file=$1
  
  cd $(dirname $target_file)
  target_file=$(basename $target_file)
  
  # Iterate down a (possible) chain of symlinks
  while [ -L "$target_file" ]; do
      target_file=$(readlink $target_file)
      cd $(dirname $target_file)
      target_file=$(basename $target_file)
  done
  
  # Compute the canonicalized name by finding the physical path 
  # for the directory we're in and appending the target file.
  phys_dir=$(pwd -P)
  result=$phys_dir/$target_file
  echo $result