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
grepas an alias forgrep --color=autoin your.bashrc, but that’s not loaded by scripts. Use an explicitgrep --colorin your script.