Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:14]
└─[$]> ll
total 0
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:14]
└─[$]> touch foo
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:14]
└─[$]> ln -s foo bar
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:14]
└─[$]> ll
total 0
lrwxrwxrwx 1 jamesph jamesph 3 Mar 23 13:14 bar -> foo
-rw-r--r-- 1 jamesph jamesph 0 Mar 23 13:14 foo
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:14]
└─[$]> set -e
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:15]
└─[$]> rm_if_link() { [ -L "$1" ] && rm -v "$1"; }
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:15]
└─[$]> rm_if_link foo
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:15]
└─[$]> ll
total 0
lrwxrwxrwx 1 jamesph jamesph 3 Mar 23 13:14 bar -> foo
-rw-r--r-- 1 jamesph jamesph 0 Mar 23 13:14 foo
┌─[jamesph@ilmr] - [~/temp/rm_if_link] - [Wed Mar 23, 01:15]
└─[$]> rm_if_link bar
removed 'bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment