pastebin46545

Bash-Script: dir and script name

Mar 9th, 2018
414
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. ###  Bash-Script: dir and script name ###
  4.  
  5. ## Setup ##
  6. if [ ! -f "/tmp/src dir/test.sh" ];
  7. then
  8.  
  9. # copy pased to terminal to run it instant ;-)
  10.    mkdir -p "/tmp/src dir/other"
  11.    cd "/tmp/src dir/"
  12.    wget -O test.sh https://pastebin.com/raw/J8KjxrPF
  13.    sed -i 's/\r//g' test.sh
  14.    chmod 700 test.sh
  15.    cd other
  16.    ../test.sh
  17. # end copy pased
  18.  
  19. fi
  20.  
  21. ## The script ##
  22. echo "Sample: \"/tmp/src dir/test.sh\" called by \"/tmp/src dir/other\""
  23. echo "See script @ Setup"
  24. echo
  25. echo Script-Dir : `dirname "$(realpath $0)"`
  26. echo Script-Dir : $( cd ${0%/*} && pwd -P )
  27. echo Script-Dir : $(dirname "$(readlink -f "$0")")
  28. echo
  29. echo Script-Name : `basename "$(realpath $0)"`
  30. echo Script-Name :  `basename $0`
  31. echo
  32. echo Script-Dir-Relative : `dirname "$BASH_SOURCE"`
  33. echo Script-Dir-Relative : `dirname $0`
  34. echo
  35. echo Calling-Dir : `pwd`
  36.  
  37. ## The output: ##
  38. # Script-Dir : /tmp/src dir
  39. # Script-Dir : /tmp/src dir
  40. # Script-Dir : /tmp/src dir
  41.  
  42. # Script-Name : test.sh
  43. # Script-Name : test.sh
  44.  
  45. # Script-Dir-Relative : ..
  46. # Script-Dir-Relative : ..
  47.  
  48. # Calling-Dir : /tmp/src dir/other
RAW Paste Data