Continuing on with trying to learn Linux, I have begun playing around with bash scripting. Currently watching a series online but with a programming background it's not difficult to pick up.

Anyway, I find myself typing "clear" and then immediately "ls" since I like to keep a clean terminal window while doing things. So I have created a bash script simply titled "cls" and moved it to /usr/bin so I can use it whenever.

It works great but I noticed it removes all the highlighting in the terminal when it outputs the directory's files and directories. You can see what I mean here. The first group of output is with my cls script, but the second group is just with typing "ls".

It's no a huge deal but I'd really like to maintain the highlighting as it could be important.

Thanks!

    Try playing with ls's [font=monospace]--color[/font] switch.

      Bonesnap;11053499 wrote:

      Continuing on with trying to learn Linux, I have begun playing around with bash scripting. Currently watching a series online but with a programming background it's not difficult to pick up.

      Anyway, I find myself typing "clear" and then immediately "ls" since I like to keep a clean terminal window while doing things. So I have created a bash script simply titled "cls" and moved it to /usr/bin so I can use it whenever.

      It works great but I noticed it removes all the highlighting in the terminal when it outputs the directory's files and directories. You can see what I mean here. The first group of output is with my cls script, but the second group is just with typing "ls".

      It's no a huge deal but I'd really like to maintain the highlighting as it could be important.

      Thanks!

      What's the script look like? Weedpacket probably has the solution; I'm just curious as to the cause. My 1st thought is that the script doesn't setup the same environment as the one the shell is setting up for your terminal....

        Weedpacket;11053505 wrote:

        Try playing with ls's [font=monospace]--color[/font] switch.

        Thanks for the tip, I'll try it out tonight!

        dalecosp;11053513 wrote:

        What's the script look like? Weedpacket probably has the solution; I'm just curious as to the cause. My 1st thought is that the script doesn't setup the same environment as the one the shell is setting up for your terminal....

        The script is pretty bare bones. Off the top of my head:

        #!/bin/bash
        
        clear
        ls
        

          Can confirm the color switch fixed it:

          #!/bin/bash
          
          clear
          ls --color=always
          

          Took me about 15 minutes to figure out why it kept complaining that the switch or whatever didn't exist and then I finally realized it was because I was spelling colour. :glare:

            Write a Reply...