Linux 为什么不是';";ls$(pwd/cat)“;工作
例如,在我的Ubuntu中:Linux 为什么不是';";ls$(pwd/cat)“;工作,linux,ls,Linux,Ls,例如,在我的Ubuntu中: $ pwd /home/yangxiaoyu/c/test 如果我说: ls /home/yangxiaoyu/c/test/cat 我得到: ls: 无法访问'/home/yangxiaoyu/c/test/cat': No such file or directory bash: pwd/cat: No such file or directory 0x2b 1.txt catfile ff readFile.c ~rootfile y
$ pwd
/home/yangxiaoyu/c/test
如果我说:
ls /home/yangxiaoyu/c/test/cat
我得到:
ls: 无法访问'/home/yangxiaoyu/c/test/cat': No such file or directory
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
但是,如果我说:
ls $(pwd/cat)
我得到:
ls: 无法访问'/home/yangxiaoyu/c/test/cat': No such file or directory
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
时,命令ls
是用给定的参数执行的
当你说ls$(某物)
时,该$(某物)
在前面得到评估。这就是您面临的问题:pwd/cat
是无效命令:
$ pwd/cat
bash: pwd/cat: No such file or directory
因此ls$(pwd/cat)
中的ls
最终没有得到任何参数,并对当前目录执行基本ls
。它还显示无效pwd/cat
命令的错误
如果要对pwd
中的cat/
项执行ls
,请说:
ls "$(pwd)"/cat
ls $PWD/cat
或者,由于当前目录是默认目录,因此只需:
ls cat
在您的“示例”中,什么是cat?我想您需要
ls$(pwd)/cat
。