shell中 ! exclamatory mark感叹号详解

 

shell中 ! 叫做事件提示符,Event Designator,可以方便的引用历史命令,即history中记录的命令

  • !n 引用第n条命令

  • !-n 引导倒数第n条命令, !-1 引用倒数第一条命令

  • !! 同 !-1

  • !string 引用最近以string开始的命令

  • !$ 传递最后执行的命令参数

     

  •  !^ 传递最后执行命令的第一个参数

     

  • !* 传递最后执行命令的所有参数


  • 取反
    ll s[!ib]* 列出第二个字符不是 "i" || "b" 的文件

    下面extglob选项必须打开

    shopt -s extglob

     

     

     

  • !?string 引用最后一条包含string的命令,跟!string不同的是 !string引用的是命令 !?string是任意位置包含string即可

     

     

输出单引号:

  • 使用''包围

     

     使用""时,shell会提示event not found

  • \ 转义

     

     

  • set +H

     

     shell中一般都默认打开H选项

     

     

     

     

     

     

posted @ 2020-10-09 21:28  ascertain  阅读(572)  评论(0编辑  收藏  举报