如何创建在执行实际命令之前更改环境变量的别名命令
首先,我很抱歉,这是一个“给我代码”的问题。不过,我保证会从您的回答中学习!这意味着如果您认为有必要,请随意使用苏格拉底方法。
我目前正在使用 Grails 和它的工作方式是它提供一个命令行 shell 来执行各种任务。
这一切都很好,但是版本之间的切换有点麻烦,因为它全部由一个名为 GRAILS_HOME
的环境变量控制,该变量被设置为指向诸如 C 之类的目录:\grails\grails-1.2.3\
。
现在,我希望能够做到这一点,而不是做这样的事情:
grails create-app MyWebApp
grails list-plugins -repository=myPluginRepo
grails install-plugin myPlugin
然后注意到我使用了错误的版本并且我必须返回,我宁愿
g135 create-app MyWebApp
g135 list-plugins -repository=myPluginRepo
g135 install-plugin myPlugin
这样做会立即告诉我我我正在使用 Grails 1.3.5。
我在创建这样的 psh 脚本时遇到的问题是我完全不擅长创建脚本。我确实尝试这样做,但在 psh 本身发出大约五个神秘错误消息后,我决定寻求建议。
奖励点:如果我可以参数化别名调用来指定版本(类似g[1.3.5]其他参数
),然后附加环境变量值的数字, 这对我来说是最方便的解决方案。
First, I'm sorry but this is kind of a "give me teh codez" question. I promise to learn from your answers, though! That means that feel free to use the Socratic method if you feel it's necessary.
I'm currently developing (both maintenance and building new ones) multiple sites using Grails and the way it works is that it provides a commandline shell for executing various tasks.
This is all fine and well, but switching between versions is a bit of a nuisance, since it's all controlled by a single environment variable called GRAILS_HOME
which is set to point to a directory such as C:\grails\grails-1.2.3\
.
Now, what I would like to be able to do that instead of doing something like this:
grails create-app MyWebApp
grails list-plugins -repository=myPluginRepo
grails install-plugin myPlugin
and then noticing that I'm using the wrong version and that I have to go back, I'd rather do
g135 create-app MyWebApp
g135 list-plugins -repository=myPluginRepo
g135 install-plugin myPlugin
which would immediately tell me that I'm using Grails 1.3.5.
The problem I have in creating a psh script like this is that I absolutely suck at creating scripts. I did try doing this but after about five mysterious error messages from psh itself I decided to just ask for advice.
Bonus points: If I can parameterize the alias call to specify the version (something like g[1.3.5] other params
) and then append the number to the environment variable value,
that'd be the most handy solution for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以做到:
它只是一个简短的函数,用于设置变量,然后如上所述执行 grails。
通过在函数名称后直接指定版本号来运行它:
This should do it:
It's just a short function that sets the variable and then executes grails as above.
Run it by specifying the version number directly after the function name: