Bash functions
When a bash alias is not enough, for example when you need to provide arguments to a command.
alias myalias="echo the args $@ provided"
Will result in
[jocc@manjaro ~]$ myalias 1 2 3
the args provided 1 2 3
When ran with the arguments 1
, 2
and 3
.
The fact that the arguments are at the end in the output shows us that they were not treated as arguments - they were just appended to the end of the aliases output.
If we instead create it like this:
myfunction () {
echo the args $@ provided
}
(You can for example put the function in yout .bashrc file, don’t forget to source it: source .bashrc
)
We will get the result
[jocc@manjaro ~]$ myfunction 1 2 3
the args 1 2 3 provided
Read other posts