Advertisement
macphail

linux bash script: $FILENAME creation

Nov 28th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.63 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #############################################################################
  4.  
  5. # enforce root permissions
  6. ROOT_UID=0
  7. E_NOTROOT=87
  8. if [ "$UID" -ne "$ROOT_UID" ]
  9. then
  10.   echo "You must be root to run this script."
  11.   exit $E_NOTROOT
  12. fi
  13.  
  14. #############################################################################
  15.  
  16. # set $UTCTIME variable
  17. UTCTIME=$(/bin/date --utc +"%Y%m%d_%H%M%Z")
  18.  
  19. #############################################################################
  20.  
  21. # generate menu
  22. prompt="Select an option:"
  23. options=("Edit TARGET variable" "Edit TOOL variable" "Display current values")
  24. PS3="$prompt "
  25. select opt in "${options[@]}" "Quit"; do
  26.  
  27.     case "$REPLY" in
  28.  
  29. #############################################################################
  30.  
  31. # option: edit TARGET variable
  32.     1 )
  33.      echo ""
  34.      echo "Editing" '$TARGET' "variable..."
  35.      sleep 2
  36.      echo "Variable" '$TARGET' "currently equals: $TARGET"
  37.      echo "Please enter your new target (lower-case, no spaces):"
  38.      read TARGET
  39.      echo "Variable" '$TARGET' "now equals: $TARGET"
  40.      echo ""
  41.      FILENAME=$TARGET\_$UTCTIME\_$TOOL
  42.      sleep 1;;
  43.  
  44. #############################################################################
  45.  
  46. # option: edit TOOL variable    
  47.     2 )
  48.      echo ""
  49.      echo "Editing" '$TOOL' "variable..."
  50.      sleep 2
  51.      echo "Variable" '$TOOL' "currently equals: $TOOL"
  52.      echo "Please enter your new tool (lower-case, no spaces):"
  53.      read TOOL
  54.      echo "Variable" '$TOOL' "now equals: $TOOL"
  55.      echo ""
  56.      FILENAME=$TARGET\_$UTCTIME\_$TOOL
  57.      sleep 1;;
  58.  
  59. #############################################################################
  60.  
  61. # option: display current values
  62.    3 )
  63.     echo ""
  64.     echo "Variable" '$TARGET' "currently equals: $TARGET"
  65.     echo "The current UTCTIME is: "$UTCTIME
  66.     echo "Variable" '$TOOL' "currently equals: $TOOL"
  67.     echo "Variable" '$FILENAME' "currently equals: $FILENAME"
  68.     sleep 1;;
  69.  
  70. ##############################################################################
  71.  
  72. # option: quit
  73.     $(( ${#options[@]}+1 )) )
  74.     echo ""
  75.     echo "Your format variable," '$FILENAME' "appears as the following:"
  76.     sleep 1
  77.     echo "$FILENAME"
  78.     echo "";
  79.       break;;
  80.  
  81. #############################################################################
  82.  
  83. # option: invalid
  84.     *)
  85.     echo ""
  86.     echo "Invalid option.";
  87.     echo ""
  88.     continue;;
  89.  
  90. #############################################################################
  91.  
  92.     esac
  93. done
  94.  
  95. # if this script is called via 'source <scriptname.sh>', then
  96. # calling 'exit' at the end of the script will close the shell.
  97.  
  98. # exit  0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement