github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/alias.md (about)

     1  # `alias`
     2  
     3  > Create an alias for a command
     4  
     5  ## Description
     6  
     7  `alias` allows you to create a shortcut or abbreviation for a longer command.
     8  
     9  IMPORTANT: aliases in Murex are not macros and are therefore different than
    10   other shells. if the shortcut requires any dynamics such as `piping`,
    11   `command sequencing`, `variable evaluations` or `scripting`...
    12   Prefer the **`function`** builtin.
    13  
    14  ## Usage
    15  
    16  ```
    17  alias alias=command parameter parameter
    18  
    19  !alias command
    20  ```
    21  
    22  ## Examples
    23  
    24  Because aliases are parsed into an array of parameters, you cannot put the
    25  entire alias within quotes. For example:
    26  
    27  ```
    28  # bad :(
    29  » alias hw="out Hello, World!"
    30  » hw
    31  exec "out\\ Hello,\\ World!": executable file not found in $PATH
    32  
    33  # good :)
    34  » alias hw=out "Hello, World!"
    35  » hw
    36  Hello, World!
    37  ```
    38  
    39  Notice how only the command `out "Hello, World!"` is quoted in `alias` the
    40  same way you would have done if you'd run that command "naked" in the command
    41  line? This is how `alias` expects it's parameters and where `alias` on Murex
    42  differs from `alias` in POSIX shells.
    43  
    44  To materialize those differences, pay attention to the examples below:
    45  
    46  ```
    47  # bad : the following statements generate errors,
    48  #  prefer function builtin to implent them
    49  
    50  » alias myalias=out "Hello, World!" | wc
    51  » alias myalias=out $myvariable | wc
    52  » alias myalias=out ${vmstat} | wc
    53  » alias myalias=out "hello" && out "world"
    54  » alias myalias=out "hello" ; out "world"
    55  » alias myalias="out hello; out world"
    56  ```
    57  
    58  In some ways this makes `alias` a little less flexible than it might
    59  otherwise be. However the design of this is to keep `alias` focused on it's
    60  core objective. To implement the above aliasing, you can use `function`
    61  instead.
    62  
    63  ## Detail
    64  
    65  ### Allowed characters
    66  
    67  Alias names can only include alpha-numeric characters, hyphen and underscore.
    68  The following regex is used to validate the `alias`'s parameters:
    69  `^([-_a-zA-Z0-9]+)=(.*?)$`
    70  
    71  ### Undefining an alias
    72  
    73  Like all other definable states in Murex, you can delete an alias with the
    74  bang prefix:
    75  
    76  ```
    77  » alias hw=out "Hello, World!"
    78  » hw
    79  Hello, World!
    80  
    81  » !alias hw
    82  » hw
    83  exec "hw": executable file not found in $PATH
    84  ```
    85  
    86  ### Order of preference
    87  
    88  There is an order of precedence for which commands are looked up:
    89  
    90  1. `runmode`: this is executed before the rest of the script. It is invoked by
    91     the pre-compiler forking process and is required to sit at the top of any
    92     scripts.
    93  
    94  1. `test` and `pipe` functions also alter the behavior of the compiler and thus
    95     are executed ahead of any scripts.
    96  
    97  4. private functions - defined via `private`. Private's cannot be global and
    98     are scoped only to the module or source that defined them. For example, You
    99     cannot call a private function directly from the interactive command line
   100     (however you can force an indirect call via `fexec`).
   101  
   102  2. Aliases - defined via `alias`. All aliases are global.
   103  
   104  3. Murex functions - defined via `function`. All functions are global.
   105  
   106  5. Variables (dollar prefixed) which are declared via `global`, `set` or `let`.
   107     Also environmental variables too, declared via `export`.
   108  
   109  6. globbing: however this only applies for commands executed in the interactive
   110     shell.
   111  
   112  7. Murex builtins.
   113  
   114  8. External executable files
   115  
   116  You can override this order of precedence via the `fexec` and `exec` builtins.
   117  
   118  ## Synonyms
   119  
   120  * `alias`
   121  * `!alias`
   122  
   123  
   124  ## See Also
   125  
   126  * [`exec`](../commands/exec.md):
   127    Runs an executable
   128  * [`export`](../commands/export.md):
   129    Define an environmental variable and set it's value
   130  * [`fexec` ](../commands/fexec.md):
   131    Execute a command or function, bypassing the usual order of precedence.
   132  * [`function`](../commands/function.md):
   133    Define a function block
   134  * [`g`](../commands/g.md):
   135    Glob pattern matching for file system objects (eg `*.txt`)
   136  * [`global`](../commands/global.md):
   137    Define a global variable and set it's value
   138  * [`let`](../commands/let.md):
   139    Evaluate a mathematical function and assign to variable (deprecated)
   140  * [`method`](../commands/method.md):
   141    Define a methods supported data-types
   142  * [`private`](../commands/private.md):
   143    Define a private function block
   144  * [`set`](../commands/set.md):
   145    Define a local variable and set it's value
   146  * [`source`](../commands/source.md):
   147    Import Murex code from another file of code block
   148  
   149  <hr/>
   150  
   151  This document was generated from [builtins/core/structs/function_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/structs/function_doc.yaml).