gpt4 book ai didi

linux - 为什么 "ls $(pwd/cat)"不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 04:45:25 25 4
gpt4 key购买 nike

以我的 Ubuntu 为例:

$ pwd
/home/yangxiaoyu/c/test

如果我说:

ls /home/yangxiaoyu/c/test/cat

我得到:

ls: 无法访问'/home/yangxiaoyu/c/test/cat': No such file or directory

但是,如果我说:

ls $(pwd/cat)

我得到:

bash: pwd/cat: No such file or directory
0x2b 1.txt catfile ff readFile.c ~rootfile yxy.h
0X2b.c a.out example list ref.c thread.c

如您所见,当我使用 $(pwd/cat) 作为 ls 的参数时,它会显示错误输出以及当前目录中的项目列表。

为什么会发生这种情况?

最佳答案

当你说ls <argument>时命令ls使用给定参数执行。

当你说ls $(something)时,即$(something)之前被评估过。这就是您面临的问题:pwd/cat是无效命令:

$ pwd/cat
bash: pwd/cat: No such file or directory

所以lsls $(pwd/cat)最终没有得到任何参数并执行基本的 ls在当前目录上。它还显示无效 pwd/cat 的错误命令。

如果你想执行ls到一个项目cat/ pwd内,说:

ls "$(pwd)"/cat

ls $PWD/cat

或者,由于当前目录是默认目录,因此:

ls cat

关于linux - 为什么 "ls $(pwd/cat)"不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39529966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com