Alias with variable in bash

You can define $1 with set, then use your alias as intended:

$ alias tail_ls='ls -l "$1" | tail'
$ set mydir
$ tail_ls

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:

  1. In ~/.bashrc add:

    sendpic () { scp "$@" [email protected]:/www/misc/Pictures/; }
    
  2. Save the file and reload

    $ source ~/.bashrc
    
  3. 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'

Tags:

Linux

Bash