我用的是 Macbook。我尝试使用os.Chdir("/tmp"),但结果是/private/tmp. 以下是我的代码:package mainimport ( "fmt" "os")func main() { s, _ := os.Getwd() fmt.Println(s) if err := os.Chdir("/tmp"); err != nil { panic(err) } s, _ = os.Getwd() fmt.Println(s)}输出是:➜ test go run main.go/Users/willy/test/private/tmp为什么?
1 回答
至尊宝的传说
TA贡献1789条经验 获得超10个赞
正如这个Apple 线程中的 chown
在 OS X 上,/tmp是/private/tmp.
$ ls -ale / | grep -i tmp
lrwxr-xr-x@ 1 root wheel 11 Aug 30 2009 tmp -> private/tmp
$
golang将syscall.Chdir()遵循该符号链接。
所以最终路径预计在 Mac OS 平台上。
- 1 回答
- 0 关注
- 209 浏览
添加回答
举报
0/150
提交
取消
