fish - 鱼壳可以处理 if 语句中的 if 语句吗?
问题描述
我试图让我的 config.fish 工作,但它没有按预期工作,我真的不明白为什么。我能做的最好的事情是猜测也许 Fish 无法处理 if 语句中的 if 语句?这是我的代码:
echo "so far so good"
if status --is-interactive
# Chips: fish plugin manager
if [ -e ~/.config/chips/build.fish ] ; . ~/.config/chips/build.fish ; end
echo "def interactive"
# Don't use vi keybindings in unknown terminals,
# since weird things can happen.
set acceptable_terms xterm-256color screen-256color xterm-termite
echo "acceptable terms: $acceptable_terms"
echo "term: $TERM"
if contains $TERM acceptable_terms
echo "good to go!"
fish_vi_key_bindings
# Load pywal colors
cat ~/.cache/wal/sequences
else
echo "why?!?!?"
end
end
我得到的是:
so far so good
def interactive
acceptable terms: xterm-256color screen-256color xterm-termite
term: xterm-termite
why?!?!?
但我希望看到的是:
so far so good
def interactive
acceptable terms: xterm-256color screen-256color xterm-termite
term: xterm-termite
good to go!
但是当我在 shell 中运行它时,如果工作正常:
❯ echo "term: $TERM / acceptable: $acceptable_terms"
term: xterm-termite / acceptable: xterm-256color screen-256color xterm-termite
❯ if contains $TERM $acceptable_terms
echo "yay!"
end
yay!
这里会发生什么?
解决方案
当然 fish 可以处理嵌套的 if 语句!
if contains $TERM acceptable_terms
缺少$
第二个变量!
if contains $TERM $acceptable_terms
推荐阅读
- filter - 在 LDAP 过滤器中添加以 ABC 开头的用户到系统
- bash - echo 行没有正确重定向到 bash 脚本?
- google-sheets - 计算值而不必指定每个值
- quantlib - Quantlib:可赎回和可回售期权的债券
- python - 从文件中读取数字时出现 KeyError
- c - C 闪烁和中断项目
- vue.js - 组件不呈现也不提供错误
- draw - 如何使用 CEP / ExtendScript 在 InDesign 中绘制图形线?
- python - 如何在保存时将 django 模型字段转换为不同的维度?
- azure-synapse - Azure Synapse 中的 OPENJSON 排序规则导致排序规则冲突错误