1 #!/usr/bin/env 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 ~ expansion in dynamic assignment
19 HOME=/home/bob
20 binding='const=~/src'
21 readonly "$binding"
22 echo $const
23 ## stdout: ~/src
24
25 #### No tilde expansion in word that looks like assignment but isn't
26 # bash and mksh mistakenly expand here!
27 # bash fixes this in POSIX mode (gah).
28 # http://lists.gnu.org/archive/html/bug-bash/2016-06/msg00001.html
29 HOME=/home/bob
30 echo x=~
31 ## stdout: x=~
32 ## BUG bash/mksh stdout: x=/home/bob
33
34 #### tilde expansion of word after redirect
35 HOME=$TMP
36 echo hi > ~/tilde1.txt
37 cat $HOME/tilde1.txt | wc -c
38 ## stdout: 3
39 ## status: 0
40
41 #### other user
42 echo ~nonexistent
43 ## stdout: ~nonexistent