G2A Many GEOs
SHARE
TWEET

asklist

tolikpunkoff May 11th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. FOUNDLST=""
  4. DIR1="/home/smallwolfie/test/archives"
  5. TARGZ=""
  6.  
  7. create_list() #$1 - dir, $2 - file mask
  8. {
  9.     FOUNDLST=""
  10.     for FLE in $(find $1 -maxdepth 1 -iname $2); do
  11.     if [ -n "$FLE" ]; then
  12.         FOUNDLST="$FOUNDLST"`basename $FLE`"\n"
  13.     fi
  14.     done
  15. }
  16.  
  17. ask_list() #$1 - list #$2 - header
  18. {
  19.     LIST_BUF=$1
  20.     echo "$2"
  21.     echo
  22.    
  23.     START_CHR=$((${#LIST_BUF}-2))
  24.     CHR_BUF=${LIST_BUF:$START_CHR:2}
  25.     if [[ "$CHR_BUF" == "\n" ]];then
  26.     LIST_BUF=${LIST_BUF::-2}
  27.     fi
  28.    
  29.     LIST_CTR=`echo -e "$LIST_BUF"|wc -l`
  30.    
  31.     echo -e "$LIST_BUF"|nl
  32.     echo -e "     C  Cancel"
  33.     echo
  34.    
  35.     while [ 1 -eq 1 ];do
  36.     read -n1 -s
  37.    
  38.     if [[ "x$REPLY" == "xC" || "x$REPLY" == "xc" ]]; then
  39.         LIST_RET="C"
  40.         return
  41.     fi
  42.    
  43.     if (echo "$REPLY" | grep -E -q "^?[0-9]+$"); then
  44.         if [ "$REPLY" -gt 0 -a "$REPLY" -le "$LIST_CTR" ]; then
  45.         LIST_RET=$REPLY
  46.         LIST_ITEM=`echo -e "$LIST_BUF"|awk -v lnum="${LIST_RET}" '(NR == lnum)'`
  47.         return
  48.         fi
  49.     fi
  50.  
  51.     done
  52. }
  53.  
  54. create_list $DIR1 "*.tar.gz"
  55.  
  56. if [ -z "$FOUNDLST" ]; then
  57.     echo "$DIR1 *.tar.gz not found"
  58.     exit
  59. else
  60.     TARGZ=$FOUNDLST
  61. fi
  62.  
  63. ask_list $TARGZ "Select file"
  64.  
  65. if [[ "$LIST_RET" == "C" ]]; then
  66.     echo "Cancelled by user"
  67. else
  68.     echo "User select item: $LIST_RET"
  69.     echo "Item value: $LIST_ITEM"
  70. fi
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top