Last active
September 7, 2017 10:35
-
-
Save mattpotts/8061681c7a535a6a9abed77beeb70c61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
# Copy specific characters from a string to the clipboard | |
# Enter empty character index to exit | |
# Read password | |
echo -n "Password: " | |
read -s password | |
echo | |
# Until enough characters have been copied.. | |
while true; do | |
# Read character index | |
echo -n "Index: " | |
read index | |
if [[ -z $index ]]; then # Empty input | |
echo "Bye" | |
exit | |
elif ! [[ $index =~ ^[0-9]+$ ]]; then # Non numeric input | |
echo "Enter a number" | |
echo | |
elif [[ $index < 1 ]]; then # Zero input | |
echo "Enter a number 1-${#password}" | |
echo | |
# elif [[ ${index} > ${#password} ]]; then # Index doesn't exist: doesn't work! | |
# echo "Enter a number 1-${#password}" | |
# echo | |
else # Copy character | |
echo "${password:$index-1:1}" | pbcopy | |
echo "Copied!" | |
echo | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment