How to take path from variable Bash -
this question has answer here:
i can't path variable in bash. how correct? example:
my@pc:~$ a="~/.bashrc" my@pc:~$ cat $a cat: ~/.bashrc: no such file or directory
didn't work, but
cat .bashrc
and
cat ".bashrc"
works well.
here right answer fedorqui
cat $(eval echo $a)
the reason issue tilde expanded home directory shell. when store in variable, tilde not expanded , cat looks file .bashrc in folder ~ (rather home directory)
there 2 ways around issue: proposed eval, , using $home:
a="$home/.bashrc"
Comments
Post a Comment