【问题标题】:Builtin Commands in UnixUnix 中的内置命令
【发布时间】:2016-01-03 06:16:45
【问题描述】:

在 Unix 或类似 Unix 的系统中,命令是“shell builtin”的类型。像 cd、echo 这样的命令是 shell 内置的。有没有什么办法 列出所有的 shell 内置命令或者是否有任何命令可以列出 shell 的所有内置命令?

【问题讨论】:

标签: linux shell unix


【解决方案1】:

查找您的 shell 的手册页。 应该有一个“SHELL BUILTIN COMMANDS”部分

$ man bash

【讨论】:

    【解决方案2】:

    这取决于外壳。因此,请阅读您的特定 shell 的文档。

    对于bash,请参阅here

    对于zsh,请参阅here

    对于fish,请参阅this

    对于tcsh(我不推荐,STFW 对于csh considered harmful),请参阅here

    有关 POSIX shell 规范,请阅读 that。如果您想以某种方式编写“可移植” shell 脚本,则应将自己限制在该规范中。

    一些救援 shell 有许多内置函数,在严重损坏或损坏的系统上很有用,例如没有更多 /bin/mv/bin/cp executables。例如sash

    一些 shell 能够加载 plugins(不知何故可能定义新的内置函数),或定义函数。

    一些 shell 有一个 restricted 形式,它删除一些内置函数(特别是 cd)。对于受限的bash,请参阅here

    【讨论】:

    • 谢谢。这些是文档。我期望的命令在以下链接中。 stackoverflow.com/a/949006/524743
    • 不幸的是,该链接特定于bash。它不适用于其他外壳。如果您的bash 已经加载了插件,那将是不完整的,或者对于受限的bash 来说可能过多
    【解决方案3】:

    TAB 显示来自 PATH 和内置命令的可用命令。
    重置你的 PATH 并输入 [TAB] 两次并回答 y

    $ PATH=
    $ [TAB][TAB]
    Display all 123 possibilities? (y or n)
    -                         compgen                   fg                        _ooexp_                   spwd
    :                         complete                  fi                        path                      startx
    !                         compopt                   for                       _pkcon                    _strip
    .                         _compreply_               function                  __pkconcomp               suspend
    ..                        continue                  _gdb_                     _pkcon_search             test
    ...                       coproc                    getopts                   popd                      then
    [                         __dbus_send               hash                      ppwd                      time
    [[                        declare                   help                      printf                    times
    ]]                        dir                       history                   pushd                     trap
    {                         dirs                      if                        pwd                       true
    }                         disown                    in                        rd                        type
    +                         do                        jobs                      read                      typeset
    alias                     done                      kill                      readarray                 ulimit
    beep                      echo                      l                         readonly                  umask
    bg                        elif                      la                        rehash                    unalias
    bind                      else                      let                       remount                   unmount
    break                     enable                    ll                        return                    unset
    builtin                   esac                      local                     _scout                    until
    caller                    eval                      logout                    _scpm                     wait
    case                      exec                      ls                        select                    while
    cd                        exit                      ls-l                      set                       _yast2
    _cd_                      _exp_                     _man_                     shift                     you
    cd..                      export                    mapfile                   shopt                     _zypper
    command                   false                     md                        skipthis
    command_not_found_handle  fc                        o                         source
    

    【讨论】:

      【解决方案4】:

      只需在shell上输入help,就会出现一个列表

      【讨论】:

        猜你喜欢
        • 2011-06-07
        • 2015-09-21
        • 2023-03-31
        • 2014-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-09
        • 1970-01-01
        相关资源
        最近更新 更多