从bash脚本运行何时grep失去着色 [英] grep loses coloring when run from bash script
问题描述
我,因为我是用相同参数的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屋!