code_junkie

unix shell script find out which directory the script file resides?

Nov 11th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. BASEDIR=$(dirname $0)
  4. echo $BASEDIR
  5.  
  6. #!/bin/bash
  7. # Absolute path to this script, e.g. /home/user/bin/foo.sh
  8. SCRIPT=`readlink -f $0`
  9. # Absolute path this script is in, thus /home/user/bin
  10. SCRIPTPATH=`dirname $SCRIPT`
  11. echo $SCRIPTPATH
  12.  
  13. #!/bin/tcsh
  14. # Absolute path to this script, e.g. /home/user/bin/foo.csh
  15. set SCRIPT=`readlink -f $0`
  16. # Absolute path this script is in, thus /home/user/bin
  17. set SCRIPTPATH=`dirname $SCRIPT`
  18. echo $SCRIPTPATH
  19.  
  20. #!/bin/bash
  21.  
  22. current_dir=$(pwd)
  23. script_dir=$(dirname $0)
  24.  
  25. echo $current_dir
  26. echo $script_dir
  27.  
  28. /
  29. /home/mez
  30.  
  31. #!/bin/bash
  32.  
  33. pushd $(dirname "${0}") > /dev/null
  34. basedir=$(pwd -L)
  35. # Use "pwd -P" for the path without links. man bash for more info.
  36. popd > /dev/null
  37.  
  38. echo "${basedir}"
  39.  
  40. cd $(dirname $(readlink -f $0))
  41.  
  42. BASEDIR=$(dirname $0)
  43. echo $BASEDIR
  44.  
  45. current_dir=$(pwd)
  46. script_dir=$(dirname $0)
  47.  
  48. if [ $script_dir = '.' ]
  49. then
  50. script_dir="$current_dir"
  51. fi
  52.  
  53. if [ -d "$Directory" -a -w "$Directory" ]
  54. then
  55. #Statements
  56. fi
  57.  
  58. "$_/../"
Add Comment
Please, Sign In to add comment