I need to find what the relative directory (relative to $HOME that is) within a bash script and, at the moment, I can only see rather messy ways of doing it.
To go into more detail I want a way to generate a string of the form ~/subdir1/subdir2 when a script is run from ~/subdir1/subdir2.
The best I can come up with at the moment is to get the full path to the current directory using pwd and then to remove $HOME from that string using sed, e.g.:-
fullpath=`pwd` relpath=`echo $fullpath | sed s#$HOME#~#`
Actually that's not quite as nasty a I thought, but it still feels like there should be a neater way. (I haven't tried it so there may well be issues with quoting etc. but you can see the idea)
Any ideas?