1 #!/bin/bash
2
3 ### ~ expansion in assignment
4 HOME=/home/bob
5 a=~/src
6 echo $a
7 # stdout: /home/bob/src
8
9 ### ~ expansion in readonly assignment
10 # dash fails here!
11 # http://stackoverflow.com/questions/8441473/tilde-expansion-doesnt-work-when-i-logged-into-gui
12 HOME=/home/bob
13 readonly const=~/src
14 echo $const
15 # stdout: /home/bob/src
16 # BUG dash stdout: ~/src
17
18 ### No tilde expansion in word that looks like assignment but isn't
19 # bash and mksh mistakenly expand here!
20 # bash fixes this in POSIX mode (gah).
21 # http://lists.gnu.org/archive/html/bug-bash/2016-06/msg00001.html
22 HOME=/home/bob
23 echo x=~
24 # stdout: x=~
25 # BUG bash/mksh stdout: x=/home/bob
26
27 ### tilde expansion of word after redirect
28 echo hi > ~/git/oil/_tmp/tilde1.txt
29 cat $HOME/git/oil/_tmp/tilde1.txt | wc -c
30 # stdout: 3
31 # status: 0