5
alias bp="cat $@ > $@.BACK"

My second idea was:

alias bp="cp $@{,.BACK}"

So i want to have a command to backup a file. It does not raise any error but it simply doesn't work.

Art.py
  • 87
  • 1
  • 3
  • It would expand at the time you define the alias. Single-quotes might help, but I'm not sure you can express what you want using aliases without a function. – 0xC0000022L Apr 03 '12 at 17:38
  • possible duplicate of [Make bash alias that takes parameter?](http://stackoverflow.com/questions/7131670/make-bash-alias-that-takes-parameter) – l0b0 Apr 04 '12 at 14:24

1 Answers1

12

Aliases are purely a textual replacement. If you want to use or manipulate the arguments, you need to create a function:

bp () {
  for file; do 
      cp -i "$file" "$file".BACK
  done
} 
Kevin
  • 53,822
  • 15
  • 101
  • 132