Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 为什么不是';";ls$(pwd/cat)“;工作_Linux_Ls - Fatal编程技术网

Linux 为什么不是';";ls$(pwd/cat)“;工作

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

例如,在我的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  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