linux - zsh 脚本 [进程完成] 没有返回到 shell

标签 linux shell zsh

我写了一个 zsh 函数来帮助我在工作中做一些 grepping。

   function rgrep (){ 
if [ -n "$1" ] && [ -n "$2" ]
then
    exec grep -rnw $1 -r $2
elif [ -n "$1" ]
then
    exec grep -rnw $1 -r "./"
else
    echo "please enter one or two args"
fi  
}

效果很好,但是,grep 完成执行我没有被扔回 shell。它只是卡在 [process complete] 有什么想法吗? 我的 .zshrc 中有函数

最佳答案

除了去掉不必要的exec,你还可以去掉if语句。

function rgrep (){
    grep -rwn "${1:?please enter one or two args}" -r "${2:-./}"
}

如果 $1 未设置(或值为 null),将引发错误并显示给定的消息。如果未设置 $2,将使用默认值 ./ 代替它。

关于linux - zsh 脚本 [进程完成] 没有返回到 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24041591/

相关文章:

php - UTF-8贯穿始终

linux - Unix Bash shell 命令在另一个 grep 匹配时 grep 一些文本

bash - Shell Bash : How to prompt a user to select from a dynamically populated list?

shell - 有没有办法自动删除tmp文件夹中的文件?

shell - 升级后 oh-my-zsh 错误 : ~/. oh-my-zsh/lib/misc.zsh:3: `then' 附近的解析错误

linux - Linux 中 "./configure"的各种选项/参数是什么

linux - 如何从文本文件中删除换行符?

python - "‘python’ : No such file or directory"when running Python file as executable

ruby-on-rails - Rails,gem,require,zsh和错误消息!由于与 “require”有关的问题,我无法加载我的应用

shell - ZSH历史完成菜单