Mailinglist Archive: opensuse (2496 mails)

< Previous Next >
Re: [opensuse] .bashrc alias - One Liner Problem?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Mon, 01 Dec 2008 12:12:24 -0600
  • Message-id: <49342908.7000002@xxxxxxxxxxxxxxxxxx>
Anders Johansson wrote:
On Sunday 30 November 2008 21:07:51 David C. Rankin wrote:
alias wp='if [[ $1 ]]; then webpin $1; else echo -e "\n\tusage: wp
<filename>\n"; fi'


I don't think you can actually pass parameters to aliases. Your previous
alias
worked because wp expanded to "webpin $1" and $1 evaluated to the blank string

You want to use a shell function instead. Something like

function wp() { if [ -n "$1" ]; then webpin $1; else echo -e "\nbad usage\n";
fi }

Anders

Thank you all!

I finally resolved to the function idea Aaron first suggested.

wpsearch ()
{
if [[ $1 ]]; then
webpin $1
else
echo -e "\n\tusage: wp <filename>\n"
fi
}

alias wp='wpsearch $1'

I guess I've been lucky using $1 with aliases. I don't know how they
work, but
they work in most instances for me:

alias hist='history | grep $1' #Requires one input
alias tmsg='sudo tail $1 -n50 /var/log/messages' # -f to follow
alias tmi='sudo tail $1 -n50 /var/log/mail.info' # -f to follow
alias umnt='/home/david/bin/alias_umnt $1'
alias wg='[[ -n $1 ]] || echo -e "\n\tUsage: wg <filename>\t\t(runs wget
--no-check-certificate --progress=bar)\n"; wget --no-check-certificate
--progress=bar $1' #requires input
alias zu='/home/david/linux/scripts/config/zypp/zypp_auto $1' # either up for
patches or -t packages for pagkages
alias znr='sudo zypper nr $1 $2' # requires two inputs <old repo alias> <new
repo alias>

That's why I was surprised to be having trouble with the webpin alias.
If I
recall correctly, I was actually introduced to the command line parameter in
aliases idea through a BASH-howto.


--
David C. Rankin, J.D.,P.E. | openSoftware und SystemEntwicklung
Rankin Law Firm, PLLC | Countdown for openSuSE 11.1
www.rankinlawfirm.com | http://counter.opensuse.org/11.1/small
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups