grep loses coloring when run from bash script

后端 未结 2 1246
旧巷少年郎
旧巷少年郎 2020-12-29 02:06

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 pro

2条回答
  •  失恋的感觉
    2020-12-29 02:07

    When you run a script, a new shell is spawned to do so. This new environment doesn't have the same settings as your default shell. As to how to get the coloring back, I'm not sure. You might try sourcing your profile at the start of the script:

    #!/bin/bash
    source $HOME/.bash_profile
    

    or whichever file makes sense on your particular unix flavor (.profile, .bash_rc, .bashrc .bash_profile) to name a few.

提交回复
热议问题