我可以链条命令多少?

发布于 2025-01-26 11:04:51 字数 420 浏览 3 评论 0原文

非常快的问题。我汇总了一些别名,以使这些乏味的蓝牙体操在过去几年中迫使我们的喉咙迫使我们的喉咙变得容易得多。我的问题是在以下bash别名中,我是否可以将多个“&”的or链链接在一起,以便我不必在.zshrc文件中制作多个别名?例如,这是我目前拥有的:

alias sonosconnect="bluetoothconnector --connect 54-2a-1b-bf-2c-dc && switchaudiosource -s SonosRoam"
alias sonos="blueutil -p 1 && sonosconnect"
alias bton="blueutil -p 1"

我的最终结果本质上是将这三个别名结合到一个长的别名中,这是通过使用多个AN&&&的实例来实现这一点?

Very quick question. I have put together a few aliases to make these tedious bluetooth gymnastics that Apple has forced down our throats over the past few years a lot easier. My question is in the following bash aliases may I chain multiple "&&'s or &'s" together so that I don't have to make multiple aliases in my .zshrc file? For instance this is what I currently have:

alias sonosconnect="bluetoothconnector --connect 54-2a-1b-bf-2c-dc && switchaudiosource -s SonosRoam"
alias sonos="blueutil -p 1 && sonosconnect"
alias bton="blueutil -p 1"

My end result would essentially be combining these 3 aliases into one long alias, is this possible by using more than one instance of an &&?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2025-02-02 11:04:52

您根本不应该使用别名。改用功能。

sonosconnect () {
  bluetoothconnector --connect 54-2a-1b-bf-2c-dc && switchaudiosource -s SonosRoam
}

sonos () { 
  blueutil -p 1 && sonosconnect
}

bton () {
  blueutil -p 1
}

some_name_for_all () {
    sonosconnect
    sonos
    bton
}

命令行可以多长时间没有显着限制,但是在很少情况下,别名是一个更好的选择,而许多 函数是更好甚至只有适当选择的情况。

You shouldn't be using aliases at all. Use functions instead.

sonosconnect () {
  bluetoothconnector --connect 54-2a-1b-bf-2c-dc && switchaudiosource -s SonosRoam
}

sonos () { 
  blueutil -p 1 && sonosconnect
}

bton () {
  blueutil -p 1
}

some_name_for_all () {
    sonosconnect
    sonos
    bton
}

There's no significant limit on how long the command line can be, but there are very few situations where an alias is a better choice than function, and many cases where a function is the better or even only appropriate choice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文