Results 1 to 6 of 6

Thread: Terminal Output Colours

  1. #1
    Join Date
    Aug 2013
    Location
    London, UK
    Beans
    311
    Distro
    Ubuntu 18.04 Bionic Beaver

    Terminal Output Colours

    I use the default terminal for commands.

    Puzzled why terminal output colours differ if I enter commands directly or via a script.

    If I enter the following direct into terminal my GREP search items are highlighted in RED

    Code:
    sudo iwlist wlp2s0 scan | grep -E 'ESSID|Signal|Quality'
    If I enter the command via a script file output same but GREP search items are in black.

    Not a major issue but nice the have searched items in RED - Is there a way of doing this via the script?

    Geoff

  2. #2
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,244
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Terminal Output Colours

    Interesting. I just learned something. By default, it switches depending on whether it is outputting to a terminal or to a pipe.
    This fixes it:
    Code:
    sudo iwlist wlp2s0 scan | grep -E --colour=always 'ESSID|Signal|Quality'

  3. #3
    Join Date
    Aug 2011
    Location
    51.8° N 5.8° E
    Beans
    5,880
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Terminal Output Colours

    One of the default settings you get as a user on Ubuntu as a small list of aliases. You can view them with the alias command. One of these aliases adds the --color=auto option to grep. These aliases aren't used when you run a script.

  4. #4
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,244
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Terminal Output Colours

    Haha - I hadn't realised that.
    Thanks, Impavidus.

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Terminal Output Colours

    https://tldp.org/LDP/abs/html/files.html has some startup files.

    At the start of my .bashrc, it checks if it is running as a script or interactive. If a script, it returns immediately. None of my custom bash functions or aliases are available. This prevents lots of script failures and self-inflicted problems.

    Before I added the check, some systems upgrades failed because I don't use the system perl most of the time. My environment configures different perl versions for custom code and some of the more specialized programs expected the system perl and system versions of perl modules. This could happen with other languages like ruby or python too.

  6. #6
    Join Date
    Aug 2013
    Location
    London, UK
    Beans
    311
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Terminal Output Colours

    Quote Originally Posted by The Cog View Post
    Interesting. I just learned something. By default, it switches depending on whether it is outputting to a terminal or to a pipe.
    This fixes it:
    Code:
    sudo iwlist wlp2s0 scan | grep -E --colour=always 'ESSID|Signal|Quality'
    Thanks Cog, that has sorted it

    Geoff

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •