Sample Header Ad - 728x90

How does the tilde expansion work within a shell variable?

3 votes
2 answers
3179 views
I came across something funny when testing my script. I can ls my directory from the shell manually if I run $ ls ~/db_backups/ test1 test2 $ However, if I assign a shell variable a dir location as such with the tilde, it doesn't work. I tried this with both single and double quotes. $ backupfolder='~/db_backups' $ echo $backupfolder ~/db_backups $ ls $backupfolder ls: cannot access '~/db_backups': No such file or directory $ What is happening with the tilde substitution inside the shell variable? Why can't I ls the directory thru the variable like I can manually with the tilde in the dir name?
Asked by Classified (529 rep)
Jul 14, 2022, 07:08 PM
Last activity: Jul 16, 2022, 06:08 AM