zoukankan      html  css  js  c++  java
  • 【Linux】将一个命令的输出发送给另外一个命令

    一个命令的输出可以作为下一个命令的输入,下一个命令的输出又会传递给下一个命令

    我们通常使用管道和子shell的方法来组合多个命令的输出

    格式

    $ cmd1 |cmd2 | cmd3

    这里的3个组合命令,cmd1的输出传递给cmd2,cmd2的输出传递给cmd3,最终出现在显示器或者文件中


    示例

    1.组合命令

    Linux:/usr/local/sbin # ls |tail  >out1.txt
    Linux:/usr/local/sbin # cat out1.txt
    first.sh
    input_param_sum.sh
    out.txt
    out1.txt
    param_v.sh
    second.sh
    sum.sh
    test1.sh
    test2.sh
    third.sh


    2.子shell法

    Linux:/usr/local/sbin # output=$( ls |cat -n )
    Linux:/usr/local/sbin # echo $output
    1 first.sh 2 input_param_sum.sh 3 out.txt 4 out1.txt 5 param_v.sh 6 second.sh 7 sum.sh 8 test1.sh 9 test2.sh 10 third.sh

    3.反引用法

    Linux:/usr/local/sbin # output1=`ls|cat -n`

    Linux:/usr/local/sbin # echo $output1
    1 first.sh 2 input_param_sum.sh 3 out.txt 4 out1.txt 5 param_v.sh 6 second.sh 7 sum.sh 8 test1.sh 9 test2.sh 10 third.sh




  • 相关阅读:
    A Bug's Life(削弱版食物链)
    The Suspects
    Find The Multiple
    Lake Counting(dfs)
    经典dfs(depth-first search)
    喝啤酒(预防老年痴呆的深度搜索)
    C语言的位运算的优势 !
    Oil Deposits
    Catch That Cow
    HTML 003 元素
  • 原文地址:https://www.cnblogs.com/OliverQin/p/10136288.html
Copyright © 2011-2022 走看看