How Can I Expand A Tilde ~ As Part Of A Variable?
21
votes
2
answers
12869
views
When I open up a bash prompt and type:
$ set -o xtrace
$ x='~/someDirectory'
+ x='~/someDirectory'
$ echo $x
+ echo '~/someDirectory'
~/someDirectory
I was hoping that the 5th line above would have went
+ echo /home/myUsername/someDirectory
. Is there a way to do this? In my original Bash script, the variable x is actually being populated from data from an input file, via a loop like this:
while IFS= read line
do
params=($line)
echo ${params}
done <"./someInputFile.txt"
Still, I'm getting a similar result, with the echo '~/someDirectory'
instead of echo /home/myUsername/someDirectory
.
Asked by Andrew
(312 rep)
Oct 20, 2017, 06:34 PM
Last activity: Dec 26, 2024, 01:34 AM
Last activity: Dec 26, 2024, 01:34 AM