a lot of commands else grep

问题描述 投票:0回答:1

有这个剧本。

if getopts "i" i; then
  grep -i | a lot of commands
else
  grep | a lot of commands
fi

问题是,我不想重复。a lot of commands 后的第一个条目进行管理,但该条目来自于一个分支(不管是 getopts 返回0或1)。我想要这样的东西 grep ${i:-defauloption} | ...defaultoption 取决于分支的结果--即在piped之前嵌入分支,而不是重复使用 a lot of commandselse 分支,但就是没有这个选项(重复的代码)。有没有可能以某种方式避免重复的代码?

bash shell pipe getopts
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.