Multiple commands in an alias for bash

前端 未结 9 1971
[愿得一人]
[愿得一人] 2020-11-29 15:05

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

gnome-screensaver
gnome-screensaver-command --lock

Right

相关标签:
9条回答
  • 2020-11-29 15:46

    So use a semi-colon:

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

    This doesn't work well if you want to supply arguments to the first command. Alternatively, create a trivial script in your $HOME/bin directory.

    0 讨论(0)
  • 2020-11-29 15:48

    Adding my 2 cents to the 11 year old discussion try this:

    alias lock="gnome-screensaver \gnome-screensaver-command --lock"

    0 讨论(0)
  • 2020-11-29 15:51

    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.

    0 讨论(0)
提交回复
热议问题