Is any alias equivalent to a function?

Tim*_*Tim -5 bash alias

  1. Is any alias equivalent to a function, in the sense that each appearance of the alias can be replaced with the function's name, and the function name in each call to the function can be replaced with the alias?

  2. If I am correct, an arbitrary alias is defined in the following form:

    alias myalias=blahblah
    
    Run Code Online (Sandbox Code Playgroud)

    Is the alias defined in the above form always equivalent to a function defined as

    myfun () { blahblah $@ }
    
    Run Code Online (Sandbox Code Playgroud)

    ?

    If not, what function is the alias equivalent to?

Thanks.

ica*_*rus 5

As the fine manual tells us, aliases are almost completely superceded by functions. Functions can do pretty much anything an alias can do, and are capable of doing a lot more as they take arguments which can be used in arbitrary order.

The thing that functions can't do is prevent the expansion of their arguments. This means that the only reason for using an alias is to set up a function call without expansion.

alias funny='set -f; _funny'
_funny(){ set +f ; do_something_with_unexpanded_args ;}
Run Code Online (Sandbox Code Playgroud)

and now you can run funny * and see the * rather than a list of the files in the current directory.