V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rizon
V2EX  ›  程序员

Linux cat <(echo 123) 这种用法叫什么?顺便分享一下 Linux 中的符号

  •  
  •   rizon ·
    othorizon · 2019-04-29 23:12:05 +08:00 · 3027 次点击
    这是一个创建于 1816 天前的主题,其中的信息可能已经有所发展或是发生改变。
    
    $ echo 123|cat -
    
    $ cat <(echo 123)
    
    $ cat <<EOF
    > 123
    > EOF
    
    
    

    分享几种 linxu 的符号用法

    然后问问 有谁知道 <()这种用法是什么??

    10 条回复    2019-04-30 13:49:31 +08:00
    xml123
        1
    xml123  
       2019-04-29 23:15:44 +08:00
    重定向
    dangyuluo
        2
    dangyuluo  
       2019-04-29 23:22:39 +08:00
    仿佛看到高中的我。`<(echo 123)`会生成一个文件描述符( fd ),然后将这个描述符定向到当前命令的 stdin or $0

    你应该也会喜欢 hear string 和 here document

    https://www.tldp.org/LDP/abs/html/x17837.html

    http://tldp.org/LDP/abs/html/here-docs.html
    iwtbauh
        3
    iwtbauh  
       2019-04-29 23:57:54 +08:00 via Android
    <()这是一种 bash 扩展。POSIX 里没有这种语法。

    如果要考虑可移植性,应该尽量避免这种写法
    msg7086
        4
    msg7086  
       2019-04-30 03:59:17 +08:00
    这都是 Bash 里的东西,和 Linux 没关系。我 Windows 下的 Bash 也支持这些东西。
    ceyes
        5
    ceyes  
       2019-04-30 08:09:09 +08:00   ❤️ 1
    $ echo 123 | cat -
    管道将 stdout 传输到 stdin,这里用“-”代表标准输出文件‘/dev/stdout ’,类似的用法还可以看下 xargs
    https://www.tldp.org/LDP/abs/html/io-redirection.html
    https://www.ibm.com/developerworks/cn/linux/l-lpic1-103-4/index.html

    $ cat <(echo 123)
    subshell 并重定向
    https://www.tldp.org/LDP/abs/html/subshells.html

    $ cat <<EOF
    > 123
    > EOF
    Here Documents,参考: http://tldp.org/LDP/abs/html/here-docs.html
    nutting
        6
    nutting  
       2019-04-30 08:43:48 +08:00
    管道和重定向,搜搜资料,windows 的命令行也有这些概念
    zbinlin
        7
    zbinlin  
       2019-04-30 09:06:14 +08:00
    flanker
        8
    flanker  
       2019-04-30 09:54:05 +08:00
    管道
    ysc3839
        9
    ysc3839  
       2019-04-30 10:33:02 +08:00 via Android
    @ceyes '-' 应该是程序自己处理的吧?执行 `echo test > -` 可以创建这个文件。
    kimiichan
        10
    kimiichan  
       2019-04-30 13:49:31 +08:00
    进程替换
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3568 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:38 · PVG 12:38 · LAX 21:38 · JFK 00:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.