Multiple commands in an alias for bash

yuriel picture yuriel · Apr 16, 2009 · Viewed 164.4k times · Source

I'd like to define an alias that runs the following two commands consecutively.

gnome-screensaver
gnome-screensaver-command --lock

Right now I've added

alias lock='gnome-screensaver-command --lock'

to my .bashrc but since I lock my workstation so often it would be easier to just type one command.

Answer

mouviciel picture mouviciel · Apr 16, 2009

Try:

alias lock='gnome-screensaver; gnome-screensaver-command --lock'

or

lock() {
    gnome-screensaver
    gnome-screensaver-command --lock
}

in your .bashrc

The second solution allows you to use arguments.