Created
May 2, 2017 13:21
-
-
Save mkweskin/1ee14f07cb0fd4a0a7aa20ef8fcbfcc3 to your computer and use it in GitHub Desktop.
Removes a line from ~/.ssh/known_hosts. Takes a number as an argument or prompts for number. (written for sed version of macOS, YMMV)
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
#!/bin/bash | |
if [ -n "$1" ] #If input arg is non-empty then move on, but if it is prompt for number | |
then | |
LINE="$1" | |
else | |
echo "Enter line to delete of ~/.ssh/known_hosts:" | |
read LINE | |
fi | |
re='^[0-9]+$' | |
if ! [[ $LINE =~ $re ]] ; then | |
echo "Error: Enter a line number to delete" >&2; exit 1 | |
fi | |
sed -i '' "$LINE"d ~/.ssh/known_hosts || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment