Results 1 to 3 of 3

Thread: Printf a coloured "space" in bash

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    23
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Printf a coloured "space" in bash

    Hello again people. I am making a bash script to show a bar graph of load averages(uptime command) TO make the bars, I want to use just coloured spaces, but for some reason it wont work. Here is what I've done.

    Code:
    $ a="Hello World"
    $ printf "%b" "\e[1;32m$a\e[0m"
    Hello World
    
    $ a=" "
    $ printf "%b" "\e[1;32m$a\e[0m"
    Gives me just a space without color. What gives? Maybe I used wrong format for printf? Because I just took that syntax with the %b and substituted with my own values. Thanks a bunch.

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    hi,

    having no sign, a space can't have colored foreground
    plus, 01 is for bold, as there is no sign to be bold...

    instead, color background:
    Code:
    printf '^[[42m%s^[[m\n' " "
    where ^[ is Ctrl-V (depending on your editor)

    printf is used to separate format from data
    Last edited by Watael; 7th December 2012 at 08:11 PM.
    «A problem clearly stated is a problem half solved.»

  3. #3
    Senior Member cfajohnson's Avatar
    Join Date
    May 2009
    Posts
    188
    Thanks
    0
    Thanked 43 Times in 36 Posts
    Rep Power
    9

    Default Use escape sequences in the printf format string

    Code:
    printf 'Colourd\e[42m%s\e[0mspace\n' ' '
    Chris F.A. Johnson <http://cfajohnson.com/shell/>
    Shell programmer and author

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Solved] Linux "/boot/grub/grub.conf" vs "/etc/grub.conf" file
    By stunn3r in forum Linux software
    Replies: 6
    Last Post: 1st November 2012, 01:09 AM
  2. Login ssh without writing always "bash"
    By valerio in forum Shell scripting
    Replies: 6
    Last Post: 30th September 2011, 01:30 PM
  3. Which is worse: "rm -rf" or "xhost +" Commands
    By kavi in forum Linux software
    Replies: 3
    Last Post: 22nd June 2011, 07:21 AM
  4. Problem about udev "ID" and "PLACE" keywords
    By blackguester in forum Linux software
    Replies: 1
    Last Post: 3rd April 2010, 03:57 PM
  5. Subtraction of float-numbers using only bash(without "bc")
    By Lovingod in forum Shell scripting
    Replies: 2
    Last Post: 4th September 2008, 01:10 AM

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41