Shell Script Tilde Expansion Shell Script Tilde Expansion shell shell

Shell Script Tilde Expansion


You will probably need to eval the variable to have it substituted correctly. One example would be to simply do

caminho=`eval "echo $caminho"`

Keep in mind that this will break if caminho contains semicolons or quotes, it will also treat backslashes as escaping, and if the data is untrusted, you need to take care that you're not the target of an injection attack.

Hope that helps.


Quoting and expansion are always tricky, especially in bash.If your own home directory is good enough, this code works (I have tested it):

if test -z $caminhothencaminho="${HOME}/IGRAFO"else  case "$caminho" in    '~')   caminho="$HOME" ;;    '~'/*) caminho="$HOME/${caminho#'~/'}" ;;     '~'*)  echo "Case of '$caminho' is not implemented" 1>&2 ;;  esacfi


Maybe use /home/${USER} instead substituting your high user level directory if if isn't /home.