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

  • 相关阅读:
    ubuntu18.04 扩展根目录 亲测有效
    mysql数据恢复
    java多线程
    jenkins安装搭建及使用
    springboot web开发
    git版本管理
    docker安装部署项目
    vue nuxt项目部署
    IntelliJ IDEA常用快捷键
    IntelliJ IDEA常用设置
  • 原文地址:https://www.cnblogs.com/biglucky/p/4892254.html
Copyright © 2011-2022 走看看