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




  • 相关阅读:
    Spring国际化模块
    广告牌 循环 轮播 图片
    ImageLoader 网络加载图片
    ProgressBar 进度条 旋转
    UI处理 线程
    权限 动态 访问
    系统 状态栏 导航栏
    对话框 dialog 整理
    修改 字体
    获取 Activity中所有的View ViewGroup
  • 原文地址:https://www.cnblogs.com/OliverQin/p/10136288.html
Copyright © 2011-2022 走看看