Skip to content

Instantly share code, notes, and snippets.

@mkweskin
Created May 2, 2017 13:21
Show Gist options
  • Save mkweskin/1ee14f07cb0fd4a0a7aa20ef8fcbfcc3 to your computer and use it in GitHub Desktop.
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)
#!/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