linux – “ls *”的输出不一致

linux – “ls *”的输出不一致,第1张

概述只是混淆了命令“ls *”的输出.我在Ubuntu 11.10和Redhat Enterprise 6.3中测试了下面的场景,得到了相同的结果. 壳牌日志 $uname -a Linux 2.6.32-279.19.1.el6.x86_64 #1 SMP Sat Nov 24 14:35:28 EST 2012 x86_64 x86_64 x86_64 GNU/Linux$echo $0 只是混淆了命令“ls *”的输出.我在Ubuntu 11.10和Redhat Enterprise 6.3中测试了下面的场景,得到了相同的结果.

壳牌日志

$uname -a   linux 2.6.32-279.19.1.el6.x86_64 #1 SMP Sat Nov 24 14:35:28 EST 2012 x86_64 x86_64 x86_64 GNU/linux$echo 
$ls *
-bash$cd test$ls$ls * *<== at first,no file/directory under current work directory*ls: cannot access *: No such file or directory$mkdir abc *<== create a new directory "abc"*$ls * *<== output of "ls *" is empty but directory "abc" has been created.*$mkdir abcd *<== create the second directory "abcd"*$ls * *<== at this point,all the directorIEs("abc" and "abcd") are displayed.*abc:abcd:

任何人都可以解释为什么在创建目录“abc”后输出“ls *”为空?谢谢.

解决方法 这主要是因为glob模式是由shell扩展的,而不是ls本身.

因此,在创建一个空的abc目录后,发出:

$ls abc

调用ls的结果就像输入一样:

$ls *

其中列出了abc的内容.由于abc为空,因此不打印任何内容.

以同样的方式,在创建abcd之后,发出:

$ls abc abcd

调用ls的结果就像输入一样:

并且由于传递了两个目录,因此ls会在列出其(空)内容之前将每个目录打印为标题.

总结

以上是内存溢出为你收集整理的linux – “ls *”的输出不一致全部内容,希望文章能够帮你解决linux – “ls *”的输出不一致所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/1029091.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存