1

A snippet of my code is shown below. The script currently closes if its not able to find the path.

[echo "could not find $REPLY, ensure the path is correct and try again"] 

Instead I would like it at this point to loop back and try to accept input again for the path. How would I do this?

while [ $choice -eq 3 ]; do

read choice
if [ $choice -eq 1 ] ; then

    echo "You have chosen to spec....  '/path/../'" 
    read
    if [ -d $REPLY ]; then
        find $REPLY -type f -printf '%TY-%Tm-%Td %.8TT %p\n '| sort -r | head -20
    else 
        echo "could not find $REPLY, ensure the path is correct and try again"
    fi
else
DisplayName
  • 11,688
HS'
  • 101
  • 1
  • 1
  • 3

2 Answers2

1
while true; do
    echo "You have chosen to spec....  '/path/../'" 
    read
    if [ -d "$REPLY" ]; then
        find "$REPLY" -type f -printf '%TY-%Tm-%Td %.8TT %p\n '| sort -r | head -20
        break
    else
        echo "could not find $REPLY, ensure the path is correct and try again"
        echo "press enter to continue..."
        read cont
    fi
done
Hauke Laging
  • 90,279
0

I would probably use while AND case:

i=0 c=3
while case "$((i+=!(c==1))).$c"   in 
      ([MAX_REPEAT_NUM].*) ! break;;
      (*.3) read c; continue      ;;
      (*.1) printf 'prompt> '
            read d || continue    ;;esac
do    [ -d "$d" ] || continue
      find "$REPLY" -type f \
            -printf '%TY-%Tm-%Td %.8TT %p\n '| 
      sort -r | head -20
done

You can test possibility branches that way.

mikeserv
  • 58,310