zoukankan      html  css  js  c++  java
  • shell常识总结

    #!/bin/bash
    cmd="ls -lt | grep ^d | awk 'NR==1 {print $9}'"
    $cmd

    这是一个获取文件夹名字的脚本,但是却提示:

    ls: cannot access |: no such file or directory

    ls: cannot access grep: no such file or directory

    ls: cannot access ^d: no such file or directory

    ls: cannot access awk: no such file or directory

    ...

    解决:

    cmd=$(ls -lt | grep ^d | awk 'NR==1 {print $9}')

    也可以改成cmd=`ls -lt | grep ^d | awk 'NR==1 {print $9}'`

    "find paths must precede expression"

    使用命令 find -iname "result*" /media/magnum/test/, 提示上面错误,修改成:
    find /media/magnum/test/ -iname "result*", 解决

    获取远程命令的执行返回值问题

    ssh xxxx@192.xx.xx.xx "test.sh; echo $?"

    这样调用,显示的结果一直是0,无论你在test.sh的最后exit 1 或者2.

    改成下面的这个形式可以正确获取返回值

    ssh xxxx@192.xx.xx.xx "test.sh; "
    echo $?

    两种不同双引号的用法结果却不同

    第一种:

    format_type='"*.c"'
    ret=`find -iname $format_type`
    echo $ret

    输出结果是空

    另外一种:

    format_type='*.c'
    ret=`find -iname "$format_type"`
    echo $ret

    输出结果是:
    GPIO.c IMU.c

  • 相关阅读:
    二分图的判定 (图)
    并查集(模板)
    数独 (dfs)
    Map <STL>
    Set <STL>
    二叉搜索树的实现
    Find a way (BFS)
    根据输入的变量,执行相应的计算公式并返回结果
    检测字符串当中x与o的数目是否相等
    根据给定的数字和字符串,生成循环指定次数的字符串
  • 原文地址:https://www.cnblogs.com/biglucky/p/4892254.html
Copyright © 2011-2022 走看看