Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
how to read in user input ~/Downloads and resolve the ~?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
guyuming
Apprentice
Apprentice


Joined: 19 Nov 2020
Posts: 251

PostPosted: Fri Jan 10, 2025 7:40 am    Post subject: how to read in user input ~/Downloads and resolve the ~? Reply with quote

I need to read user input file path such as ~/Download with readline history, and resolve it with realpath.

however, the file_path variable value seems to have single quotation mark around it, so realpath says file not found in Chinese.

but if i echo $file_path, no single quotation mark shown.

How can I resolve user input from ~/Downloads into /home/guyuming/Downloads then?

Code:
guyuming@localhost ~ $ read -e -r file_path
~/Downloads
guyuming@localhost ~ $ realpath $file_path
realpath: '~/Downloads': 没有那个文件或目录
guyuming@localhost ~ $ echo $file_path
~/Downloads
guyuming@localhost ~ $ realpath '~/Downloads'
realpath: '~/Downloads': 没有那个文件或目录
guyuming@localhost ~ $ realpath ~/Downloads
/home/guyuming/Downloads
guyuming@localhost ~ $
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum