github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/lib/env/env.go (about) 1 // Package env contains functions for dealing with environment variables 2 package env 3 4 import ( 5 "os" 6 7 homedir "github.com/mitchellh/go-homedir" 8 ) 9 10 // ShellExpand replaces a leading "~" with the home directory" and 11 // expands all environment variables afterwards. 12 func ShellExpand(s string) string { 13 if s != "" { 14 if s[0] == '~' { 15 newS, err := homedir.Expand(s) 16 if err == nil { 17 s = newS 18 } 19 } 20 s = os.ExpandEnv(s) 21 } 22 return s 23 }