While I was reading Z-Shell guide, here is one thing that I have never thought about: using alias to work around example commands in order to execute them:

If you’re reading an electronic version of this guide, and want to copy lines with the `%' in front into a terminal to be executed, there’s a neat way of doing this where you don’t even have to edit the line first:

alias %=' '

Warning

You should never ever copy-and-paste commands and execute without even understanding them fully.

It got me thinking, you can even alias to echo, so you can get parameter expansion to work for you and get a list of ready-to-run command that’s already expanded. Again, read the warning above.

However, even this is ingenious in some way, it might not work if the leading character isn’t the right one. In Bash, % is fine, but not for more common $ and #, which are conventionally representing the commands are meant for normal user and root user, respectively.

The former, if you do run with $ directly, you get a “command not found” error; the latter, that’s a comment. For that, for a guide, it’s a much better using leading character to write example commands, because even users copy-and-paste, they wouldn’t do any harm, they would just be comments.

If you try to alias or make them functions, since they are not valid names or identifiers, so this alias trick wouldn’t work on them. Nonetheless, you can still make an executable $ script, set the PATH, run example commands with leading $.

Or you can simply write a script, processing one line at time, dropping first argument, and executing with the rest.

After all, alias %=' ' is nice to know, but should anyone use it? No.