有这个剧本。
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 commands
与 else
分支,但就是没有这个选项(重复的代码)。有没有可能以某种方式避免重复的代码?