mirror of
https://github.com/fish-shell/fish-shell
synced 2024-09-20 14:32:04 +00:00
docs: Add something on variables-as-commands
Specifically point towards the necessary splitting (as always, separate ahead of time) and the keyword thing. Fixes #9797
This commit is contained in:
parent
aac30367bf
commit
b435fc4539
2 changed files with 24 additions and 0 deletions
|
@ -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**
|
||||
|
|
|
@ -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 <command>` decorator, but only uses like ``$cmd -q foo``.
|
||||
|
||||
|
||||
.. _expand-command-substitution:
|
||||
|
||||
Command substitution
|
||||
|
|
Loading…
Reference in a new issue