我在一个文件中有以下内容,该文件由.bashrc和.zshrc提供。语法来自站点。
if $SHELL=/bin/zsh
then
# to not java .class when running java
myclasslist () { reply=(${$(ls *.class)%.class}) }
compctl -K myclasslist java
fiZsh和Bash都对此感到不安。
如何在sh中生成if -clause?
发布于 2009-07-14 21:41:13
您需要在test操作符中包装您的条件(以及用于养成习惯的引号):
空壳:
#!/bin/sh
if [ "$SHELL" = "/bin/zsh" ]; then
# do your thing
fi在巴什:
#!/bin/bash
if [ "$SHELL" == "/bin/zsh" ]; then
# just do it!
fi发布于 2009-07-14 21:41:48
您需要test别名[命令:
if [ "$SHELL" = "/bin/zsh" ]
then
myclasslist () { reply=(${$(ls *.class)%.class}) }
compctl -K myclasslist java
fi发布于 2009-07-14 21:49:44
在您提到的网站上,它们不使用test运算符([]),因为它们说:
例如,cat成功运行时返回0,如果遇到错误则返回1。
if必须后面跟着一个"boolean语句“,如果该语句返回0,则实际执行.
就你而言,赛斯的回答是你要找的东西。
https://stackoverflow.com/questions/1128207
复制相似问题