Skip to main content
added 144 characters in body
Source Link
m0dular
  • 1.3k
  • 7
  • 8

One possible answer:

eval echo "$x"

Since you're reading input from a file, I would not do this.

You could search and replace the ~ with the value of $HOME, like this:

x='~/.config'
x="$x=${x//\~#\~/$HOME${HOME}"}
echo "$x"

Gives me:

/home/adrian/.config

EDIT: changed the search and replace to ${x/#\~/${HOME}} in order to only replace the initial ~. Thanks @user137369 for the suggestion.

One possible answer:

eval echo "$x"

Since you're reading input from a file, I would not do this.

You could search and replace the ~ with the value of $HOME, like this:

x='~/.config'
x="${x//\~/$HOME}"
echo "$x"

Gives me:

/home/adrian/.config

One possible answer:

eval echo "$x"

Since you're reading input from a file, I would not do this.

You could search and replace the ~ with the value of $HOME, like this:

x='~/.config'
x=${x/#\~/${HOME}}
echo "$x"

Gives me:

/home/adrian/.config

EDIT: changed the search and replace to ${x/#\~/${HOME}} in order to only replace the initial ~. Thanks @user137369 for the suggestion.

Source Link
m0dular
  • 1.3k
  • 7
  • 8

One possible answer:

eval echo "$x"

Since you're reading input from a file, I would not do this.

You could search and replace the ~ with the value of $HOME, like this:

x='~/.config'
x="${x//\~/$HOME}"
echo "$x"

Gives me:

/home/adrian/.config