grep 在 bash 脚本中失败,但在命令行上工作 [英] grep fails inside bash script but works on command line

查看:26
本文介绍了grep 在 bash 脚本中失败,但在命令行上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

The bash file:

#!/bin/bash    
grep -l -r "products" Products/

gives output

: No such file or directory

When run directly from the terminal prompt, grep -l -r "products" Products/ gives the desired output, which is the list of files containing the word.

I checked using echo $SHELL that the shell is indeed bash so there should be no difference. What could be the reason? (Products/ directory contains around 3500 files).

Running on Ubuntu 12.04 LTS.

解决方案

Your script contains a CR at the end of the grep line. Use dos2unix to remove it.

这篇关于grep 在 bash 脚本中失败,但在命令行上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆