Expand tilde to home directory

后端 未结 5 2251
北海茫月
北海茫月 2020-12-06 04:06

I have a program that accepts a destination folder where files will be created. My program should be able to handle absolute paths as well as relative paths. My problem is t

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 04:19

    In general the ~ is expanded by your shell before it gets to your program. But there are some limitations.

    In general is ill-advised to do it manually in Go.

    I had the same problem in a program of mine and what I have understood is that if I use the flag format as --flag=~/myfile, it is not expanded. But if you run --flag ~/myfile it is expanded by the shell (the = is missing and the filename appears as a separate "word").

提交回复
热议问题