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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -