Advertisement
metalx1000

Basic File Selection

Dec 28th, 2015
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. getFile(){
  4.   clear
  5.   PS3="Please Select a File: "
  6.   options=($(find -maxdepth 1 -print0|xargs -0))
  7.  
  8.   select opt in "${options[@]}" "Quit";
  9.   do
  10.     if (( REPLY == 1 + ${#options[@]}))
  11.     then  
  12.       exit
  13.     elif (( REPLY > 0 && REPLY <= ${#options[@]} ))
  14.     then
  15.       opt=$(basename $opt)
  16.       echo "Your file is $opt"
  17.       break
  18.     else
  19.       echo "Not a Valid option.  Please Try again."
  20.     fi
  21.   done
  22.  
  23.   FILE="`pwd`/$opt"
  24. }
  25.  
  26. if [ ! -f "$FILE" ]
  27. then
  28.   while [ 1 ]
  29.   do
  30.     getFile
  31.     [[ -d "$FILE" ]] && cd "$FILE"
  32.     [[ -f "$FILE" ]] && break  
  33.   done
  34. fi
  35.  
  36. cat "$FILE"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement