[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash argument expanded inside alias



rcb <rcb@beco.cc> wrote:
> And I can run my alias without using a function, just typing:
> $ muda -10

> Unfortunately, you cannot, for example, change the directory with an
> argument, because 'find' can't accept a command in an inverted order
> like:
> $find -mtime -10 /home/kilemal

And the function is trivial. Just pop it in your .bashrc

  muda() { local M="$1" D="$2"; find "${D:-.}" -mtime -"${M:-1}"; }

  muda          # Find from "." anything modified within 1 day
  muda 3        # Find from "." anything modified within 3 days
  muda 2 /tmp   # Find from "/tmp/" anything modified within 2 days

Or if you really don't want a function, create a script and drop it
into $HOME/bin

  mkdir -p "$HOME"/bin; cat > "$HOME"/bin/muda <<x
  #!/bin/sh
  #
  M="$1" D="$2"
  find "${D:-.}" -mtime -"${M:-1}"
  x
  chmod a+x "$HOME"/bin/muda


Why are you so reluctant to use functions? Even the bash man page says,
"For almost every purpose, aliases are superseded by shell functions."

Puzzled.
Chris


Reply to: