Define an alias for a system command. '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' Then, typing 'alias_name params' will execute the system command 'cmd params' (from your underlying operating system). Aliases have lower precedence than magic
(self, parameter_s='')
| 94 | @skip_doctest |
| 95 | @line_magic |
| 96 | def alias(self, parameter_s=''): |
| 97 | """Define an alias for a system command. |
| 98 | |
| 99 | '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd' |
| 100 | |
| 101 | Then, typing 'alias_name params' will execute the system command 'cmd |
| 102 | params' (from your underlying operating system). |
| 103 | |
| 104 | Aliases have lower precedence than magic functions and Python normal |
| 105 | variables, so if 'foo' is both a Python variable and an alias, the |
| 106 | alias can not be executed until 'del foo' removes the Python variable. |
| 107 | |
| 108 | You can use the %l specifier in an alias definition to represent the |
| 109 | whole line when the alias is called. For example:: |
| 110 | |
| 111 | In [2]: alias bracket echo "Input in brackets: <%l>" |
| 112 | In [3]: bracket hello world |
| 113 | Input in brackets: <hello world> |
| 114 | |
| 115 | You can also define aliases with parameters using %s specifiers (one |
| 116 | per parameter):: |
| 117 | |
| 118 | In [1]: alias parts echo first %s second %s |
| 119 | In [2]: %parts A B |
| 120 | first A second B |
| 121 | In [3]: %parts A |
| 122 | Incorrect number of arguments: 2 expected. |
| 123 | parts is an alias to: 'echo first %s second %s' |
| 124 | |
| 125 | Note that %l and %s are mutually exclusive. You can only use one or |
| 126 | the other in your aliases. |
| 127 | |
| 128 | Aliases expand Python variables just like system calls using ! or !! |
| 129 | do: all expressions prefixed with '$' get expanded. For details of |
| 130 | the semantic rules, see PEP-215: |
| 131 | https://peps.python.org/pep-0215/. This is the library used by |
| 132 | IPython for variable expansion. If you want to access a true shell |
| 133 | variable, an extra $ is necessary to prevent its expansion by |
| 134 | IPython:: |
| 135 | |
| 136 | In [6]: alias show echo |
| 137 | In [7]: PATH='A Python string' |
| 138 | In [8]: show $PATH |
| 139 | A Python string |
| 140 | In [9]: show $$PATH |
| 141 | /usr/local/lf9560/bin:/usr/local/intel/compiler70/ia32/bin:... |
| 142 | |
| 143 | You can use the alias facility to access all of $PATH. See the %rehashx |
| 144 | function, which automatically creates aliases for the contents of your |
| 145 | $PATH. |
| 146 | |
| 147 | If called with no parameters, %alias prints the current alias table |
| 148 | for your system. For posix systems, the default aliases are 'cat', |
| 149 | 'cp', 'mv', 'rm', 'rmdir', and 'mkdir', and other platform-specific |
| 150 | aliases are added. For windows-based systems, the default aliases are |
| 151 | 'copy', 'ddir', 'echo', 'ls', 'ldir', 'mkdir', 'ren', and 'rmdir'. |
| 152 | |
| 153 | You can see the definition of alias by adding a question mark in the |
nothing calls this directly
no test coverage detected