我想定义一个别名,连续运行以下两个命令。
gnome-screensaver
gnome-screensaver-command --lock
现在我添加了
alias lock='gnome-screensaver-command --lock'
到我的.bashrc,但由于我经常锁定我的工作站,只输入一个命令会更容易。
我想定义一个别名,连续运行以下两个命令。
gnome-screensaver
gnome-screensaver-command --lock
现在我添加了
alias lock='gnome-screensaver-command --lock'
到我的.bashrc,但由于我经常锁定我的工作站,只输入一个命令会更容易。
当前回答
在windows中,在Git\etc\bash.bashrc中 我使用(在文件末尾)
a(){
git add $1
git status
}
然后在git bash中简单地写
$ a Config/
其他回答
在11岁的讨论中加入我的2点意见,试试这个:
别名锁="gnome-screensaver \gnome-screensaver-command——lock"
function lock() {
gnome-screensaver
gnome-screensaver-command --lock
}
上面的代码在bash中翻译得很好:
bottom() {
clear
printf '\n%.0s' {1..100}
}
alias c="bottom"
All I wanted to do was clear the screen (c alias) and have the bash prompt appear at the bottom, not top of terminal window. I had solved this long ago (too long ago... forgot what I did), but now I've put the function in .bash_profile and it's off to the races! For now, I am also executing the function so that when I open a new term. window, the prompt, and only the prompt, appears at the bottom. Thanks much for the suggestion. I'm not sure if I just miss this kind of stuff or miss getting paid for it... probably both. :-)
这样不行吗?
alias whatever='gnome-screensaver ; gnome-screensaver-command --lock'
Try:
alias lock='gnome-screensaver; gnome-screensaver-command --lock'
or
lock() {
gnome-screensaver
gnome-screensaver-command --lock
}
在你的。bashrc
第二个解决方案允许使用参数。
其他答案充分回答了这个问题,但是您的示例看起来第二个命令依赖于第一个命令成功退出。你可能想在你的别名中尝试短路计算:
alias lock='gnome-screensaver && gnome-screensaver-command --lock'
现在,除非第一个命令成功,否则甚至不会尝试第二个命令。在这个SO问题中对短路评估进行了更好的描述。