linux - How can I replace a leading tilde ~ with the value of $HOME, or vice versa, in a bash string-variable? -
this question has answer here:
the string variable here pathname file. should simple solution, possibly useful others.
this problem came while writing simple bash function in .bashrc
; see this thread.
~
-> $home
this duplicative of how manually expand special variable (ex: ~ tilde) in bash
$home
-> ~
this 1 of places you're better off fixing users adding workarounds (which have surprising effects) code. said...
copy() { local src=$1 dest=$2 [[ $dest = $home/* ]] && dest="~/${dest#"$home/"}" scp "$src" "$dest" }
Comments
Post a Comment