To pass command line arguments to a Bash alias command, you can use the $*
special variable to expand the list of arguments passed to the alias.
For example, consider the following Bash alias:
alias ls='ls -lh $*'
This alias defines a ls
command that runs the ls
command with the -lh
options and expands the list of arguments passed to the alias.
To use this alias, you can simply run the ls
command with the desired arguments. For example:
ls /tmp
This will run the ls -lh /tmp
command, which will list the contents of the /tmp
directory in long format with human-readable file sizes.
You can also use the $1
, $2
, $3
, etc. variables to access specific arguments passed to the alias. For example:
alias echo='echo $1 $2'
This alias defines an echo
command that prints the first and second arguments passed to the alias. To use this alias, you can run the echo
command with two arguments. For example:
echo Hello World
This will run the echo Hello World
command, which will print "Hello World" to the console.
Keep in mind that Bash aliases are a convenient way to define short commands that expand to longer commands or sequences of commands. You can use the special variables described above to pass command line arguments to Bash aliases and customize their behavior.