I’m new to linux and starting from the basics.
—
I thought alias is used to make a shortcut to a command.
But I tried the following using a variable (in Ubuntu) and still works!
$ foo="mkdir Directory"
$ $foo #this will create a directory named Directory
using alias:
$ alias bar="mkdir Directory"
$ bar #creates a Directory named directory
Is that how it is supposed to work?
Many thanks for the answers 🙂
Variables are much more versatile than aliases. Variables can be used anywhere in a command line (e.g. as parts of program arguments), whereas aliases can only be used as the names of programs to run, i.e. as the first word in a command line. For example:
Variables can also be exported into the environment of child processes. If you use the
exportbuiltin to export variables, then programs can usegetenv(3)function to get the variables’ values.See the Bash manual for a full description of all of the different types of expansions it can perform and how it performs them. See also the section on aliases.