bash 别名中的多个命令 [英] Multiple commands in an alias for bash

查看:25
本文介绍了bash 别名中的多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个别名来连续运行以下两个命令.

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

gnome-screensaver
gnome-screensaver-command --lock

现在我已经添加了

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

到我的 .bashrc 但因为我经常锁定我的工作站,所以只输入一个命令会更容易.

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

推荐答案

尝试:

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

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

在你的 .bashrc 中

in your .bashrc

第二种解决方案允许您使用参数.

The second solution allows you to use arguments.

这篇关于bash 别名中的多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆