Created
December 30, 2021 16:51
-
-
Save anikolaienko/1d0b531325ff3613f6daad271a55bbba to your computer and use it in GitHub Desktop.
Bash: Read folder path until valid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Accept either empty path or valid path | |
while [ -z $path_confirm ]; do | |
read -rp 'Type folder path (relative to current):' folder_path | |
path_confirm="y" | |
if [ ! -z $folder_path ] && [[ ! -d $folder_path ]]; then | |
read -rp 'Path does not exist. Do you want to type it again? [y/n]:' path_confirm | |
if [[ $path_confirm = "y" ]] || [[ $path_confirm = "Y" ]]; then | |
unset path_confirm | |
fi | |
fi | |
done | |
echo "Result path: [$(pwd)/$folder_path]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment