bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.
BASH Alias is a shortcut to run commands using some mapping. It is a way to create some shortcut commands for repetitive and multiple tasks. We create an alias in a BASH environment in specified files. We can also incorporate BASH functions, variables, etc to make the Alias more programmatic and flexible.
Bash users need to understand that alias cannot take arguments and parameters. But we can use functions to take arguments and parameters while using alias commands.
As with Bash aliases in general, you can put your gc alias in ~/. bashrc or in ~/. bash_aliases but it should not go in .
I'd create a function for that, rather than alias, and then exported it, like this:
function tail_ls { ls -l "$1" | tail; }
export -f tail_ls
Note -f
switch to export
: it tells it that you are exporting a function. Put this in your .bashrc
and you are good to go.
The solution of @maxim-sloyko did not work, but if the following:
In ~/.bashrc add:
sendpic () { scp "$@" [email protected]:/www/misc/Pictures/; }
Save the file and reload
$ source ~/.bashrc
And execute:
$ sendpic filename.jpg
original source: http://www.linuxhowtos.org/Tips%20and%20Tricks/command_aliases.htm
alias tail_ls='_tail_ls() { ls -l "$1" | tail ;}; _tail_ls'
You can define $1
with set
, then use your alias as intended:
$ alias tail_ls='ls -l "$1" | tail'
$ set mydir
$ tail_ls
tail_ls() { ls -l "$1" | tail; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With