Differences between fish and bash to pass commandline arguments to alias functions?

This second command is actually a small bash-script. Bash is the programming language built into the shell. It's used by other shells, but not necessarily, as we see here.

Fish defines a completely different programming language to bash, though it does support simple aliases in the usual alias name=command form; You should define a function instead. This is how you would define the above function in fish:

stefano@lenovo ~> function lsp
                      ls -ah --color=always $argv | less -R
                  end

and funcsave lsp so save it permanently.

You can now run the expected commands, like lsp, lsp -R, lsp *.png* and so on.

You can also 'invoke' bash to run a script for you, using the 'sh' program (this will run 'dash' to be precise). But if you're using fish, chances are you want to use the methods it provides. I've just tested it for the first time, and I'm very impressed so far.

The functions are stored as a file in .config/fish/functions/ in your home directory. The file name will be, in this example, lsp.fish. You can either edit the file, restarting fish afterwards, or just define and save the function again.

The best way to learn fish is by reading its built-in help. From within fish, just type

help

and you'll get a very nicely formatted, extensive and easy to read manual. Actually, this opens the w3m web browser, because the help is in html format:

alt text

(press q-y to exit)


I've never seen a contraption like this before.

alias lsp='_(){ ls -ah --color=always $* | less -R; }; _'

An alias that declares a function and runs it. You should just make a function in the first place. In bash, functions supersede aliases in almost every way.

lsp() { ls -ah --color=always "$@" | less -R; }

Put that in your ~/.bashrc file, or if you prefer to put functions in a separate file, like ~/.bash_functions then you can do that, but you have to source that file from ~/.bashrc