The string variable here is the pathname to some file. Should be a simple solution, possibly useful to others.
This problem came up while I was writing a simple bash function in my .bashrc
; see this thread.
The string variable here is the pathname to some file. Should be a simple solution, possibly useful to others.
This problem came up while I was writing a simple bash function in my .bashrc
; see this thread.
~
-> $HOME
This is duplicative of How to manually expand a special variable (ex: ~ tilde) in bash
$HOME
-> ~
This is one of those places where you're better off fixing your users than adding workarounds (which are likely to have surprising effects) to your code. That said...
copy() {
local src=$1 dest=$2
[[ $dest = $HOME/* ]] && dest="~/${dest#"$HOME/"}"
scp "$src" "$dest"
}