diff --git a/doc_src/cmds/command.rst b/doc_src/cmds/command.rst index 24f6147a4..d4f046835 100644 --- a/doc_src/cmds/command.rst +++ b/doc_src/cmds/command.rst @@ -15,6 +15,8 @@ Description **command** forces the shell to execute the program *COMMANDNAME* and ignore any functions or builtins with the same name. +In ``command foo``, ``command`` is a keyword. + The following options are available: **-a** or **--all** diff --git a/doc_src/language.rst b/doc_src/language.rst index cb628aa64..29cb83751 100644 --- a/doc_src/language.rst +++ b/doc_src/language.rst @@ -747,6 +747,28 @@ Some more examples:: # The second element of every variable, so output is # 2 5 +Variables as command +'''''''''''''''''''' + +Like other shells, you can run the value of a variable as a command. + +:: + + > set -g EDITOR emacs + > $EDITOR foo # opens emacs, possibly the GUI version + +If you want to give the command an argument inside the variable it needs to be a separate element:: + + > set EDITOR emacs -nw + > $EDITOR foo # opens emacs in the terminal even if the GUI is installed + > set EDITOR "emacs -nw" + > $EDITOR foo # tries to find a command called "emacs -nw" + +Also like other shells, this only works with commands, builtins and functions - it will not work with keywords because they have syntactical importance. + +For instance ``set if $if`` won't allow you to make an if-block, and ``set cmd command`` won't allow you to use the :cmds:`command ` decorator, but only uses like ``$cmd -q foo``. + + .. _expand-command-substitution: Command substitution