从bash脚本运行何时grep失去着色 [英] grep loses coloring when run from bash script

查看:143
本文介绍了从bash脚本运行何时grep失去着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,因为我是用相同参数的grep命令,多次写了一个简单的bash脚本。我是从〜/ bin中运行它,它运行得很好。

我的问题是:当它通过我的bash脚本运行所有的着色消失。相同的指令摆正进入命令行很好色codeS行号,文件名等。

下面是我的bash脚本

 #!/斌/庆典
#MyFolder中,递归内和行号grep的PHP文件grep的-rn --include =*。PHP的$ 2的/ home / ME / MyFolder中/ $ 1


解决方案

您可能已经定义的的grep 为的别名的grep --color =汽车的.bashrc ,但这不是由脚本加载。使用一个明确的的grep --color 在你的脚本。

I wrote a simple bash script because I was using a grep command with the same arguments, repeatedly. I'm running it from ~/bin and it runs just fine.

My problem is: All the coloring is gone when it's run through my bash script. The exact same command put right into the commandline nicely color codes line numbers, filenames, etc.

Here's my bash script

#!/bin/bash
# grep php files inside of myfolder, recursively and with line numbers

grep -rn --include="*.php" "$2" /home/me/myfolder/$1

解决方案

You've probably defined grep as an alias for grep --color=auto in your .bashrc, but that's not loaded by scripts. Use an explicit grep --color in your script.

这篇关于从bash脚本运行何时grep失去着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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