#!/bin/sh file=/tmp/sudo-password while true; do read -r -s -p "Your password please: " password res=$(echo "$password" | sudo -S -k -l) echo $res if [ "$res" == "" ]; then echo "Incorrect password, try again..." else break; fi done rm $file --force # to ignore if it isn't there touch $file echo "$password" > $file