Short Tip: Create a “bash alias” with an argument

shell.png
I always check for changes in rpm files. Unfortunately, the command to do so needs some typing:

rpm -q --changelog PACKAGENAME|most

(Btw., most is a replacement for less). The best idea would be to have a bash/zsh/whatever alias with an argument. This is unfortunately difficult or even impossible, but it is quite easy to define a simple function:

rpmch () { rpm -q --changelog "$1"|most;}

Copy that string to your .zshrc or .bashrc and you can easily query the changelog of rpm packages with the command

rpmch PACKAGENAME

This of course works for other commands as well.

About these ads

9 Responses to “Short Tip: Create a “bash alias” with an argument”

  1. cm Says:

    Looks like the definition is truncated. It works for me if I add “; }” (without the quotes).

  2. liquidat Says:

    Yes, sorry, the } was missing. I don’t have to add a ; though…

  3. ndim Says:

    Another very useful function working in that way:
    mkcd() { mkdir -p “$1″ && cd “$1″; }

  4. Francis Giannaros Says:

    Another handy one is this alias for rpm -qa (which is faster to process and quicker to type).

  5. Francis Giannaros Says:

    Dang, the URL for the above comment should have been: http://dev-loki.blogspot.com/2007/04/rpm-qa.html

  6. RichiH Says:

    Assuming you are using, and putting up with, `most` for the color ability, I suggest adding

    if [[ -x ` which less` ]]
    export LESSCHARSET="utf-8"
    then
        export PAGER="less"
        if [ $terminfo[colors] -ge 8 ]
        then
            export LESS_TERMCAP_mb=$'\E[01;31m'
            export LESS_TERMCAP_md=$'\E[01;31m'
            export LESS_TERMCAP_me=$'\E[0m'
            export LESS_TERMCAP_se=$'\E[0m'
            export LESS_TERMCAP_so=$'\E[01;44;33m'
            export LESS_TERMCAP_ue=$'\E[0m'
            export LESS_TERMCAP_us=$'\E[01;32m'
        fi
    else
        export PAGER="more"
    fi
    

    to your RC files

  7. liquidat Says:

    RichH, actually I’m using most because it shows me on which line I am. And it always reminds me how to find the help :)
    Anyway, what would happen when i use the commands above?

  8. Livio Says:

    rpmch () { rpm -q --changelog "$1"| most }

    Instead you can use:

    alias rpmch='rpm -q --changelog $1|most'

  9. Cronus Says:

    that won’t work


Comments are closed.

Follow

Get every new post delivered to your Inbox.

Join 84 other followers

%d bloggers like this: