Skip to main content
added 228 characters in body
Source Link

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ [ -z "${PWD%%$HOME*}" ] && echo ${PWD/$HOME/'~'} || echo $PWD
~/Documents

$ pwd
/etc/systemd/network
$ [ -z "${PWD%%$HOME*}" ] && echo ${PWD/$HOME/'~'} || echo $PWD
/etc/systemd/network

$ pwd
/tmp/home/kali/Documents
$ [ -z "${PWD%%$HOME*}" ] && echo ${PWD/$HOME/'~'} || echo $PWD
/tmp/home/kali/Documents

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|""s|^$HOME|~|"
~/Documents

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

$ pwd
/etc/systemd/network
$ echo ${PWD/$HOME/'~'}
/etc/systemd/network

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ [ -z "${PWD%%$HOME*}" ] && echo ${PWD/$HOME/'~'} || echo $PWD
~/Documents

$ pwd
/etc/systemd/network
$ [ -z "${PWD%%$HOME*}" ] && echo ${PWD/$HOME/'~'} || echo $PWD
/etc/systemd/network

$ pwd
/tmp/home/kali/Documents
$ [ -z "${PWD%%$HOME*}" ] && echo ${PWD/$HOME/'~'} || echo $PWD
/tmp/home/kali/Documents

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|^$HOME|~|"
~/Documents
added 20 characters in body
Source Link

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

$ pwd
/etc/sasl2systemd/network
$ echo ${PWD/$HOME/'~'}
/etc/sasl2systemd/network

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

$ pwd
/etc/sasl2
$ echo ${PWD/$HOME/'~'}
/etc/sasl2

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

$ pwd
/etc/systemd/network
$ echo ${PWD/$HOME/'~'}
/etc/systemd/network

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents
added 83 characters in body
Source Link

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

$ pwd
/etc/sasl2
$ echo ${PWD/$HOME/'~'}
/etc/sasl2

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents

I know this is an old question but you can use string operators for that purpose:

$ pwd
/home/kali/Documents
$ echo ${PWD/$HOME/'~'}
~/Documents

$ pwd
/etc/sasl2
$ echo ${PWD/$HOME/'~'}
/etc/sasl2

Now, you specifically asked about sed, I don't think it's the best tool or even necessary but you'd do:

$ pwd | sed "s|$HOME|~|"
~/Documents
added 15 characters in body
Source Link
Loading
Source Link
Loading