Options

One for the Guild of Linux ( Bash related question )

ally_ukally_uk Member Posts: 1,145 ■■■■□□□□□□
Evening all :) or should I say morning it's 3.31 am here lol couldn't sleep :P

Anyways working on a Bash script and I am trying to get the text to output in bold! now this may be something trivial to you guys but for the life of me I cannot get the flipping thing to work.

So at the start of my script I have the following variable declared.

bold="\033[1m"
normal="\033[0m"
greentext="\033[32m"

And at the start of the script I have:

echo -e $bold "Quick System report for "$greentext"$HOSTNAME"normal


But the code doesn't output bold text, I looked briefly online and somewhere mentioned something about tput? I tried that aswell but that didn't work please help me almighty gurus :)
Microsoft's strategy to conquer the I.T industry

" Embrace, evolve, extinguish "

Comments

  • Options
    DoubleNNsDoubleNNs Member Posts: 2,015 ■■■■■□□□□□
    I'm no guru - I'm actually a beginner myself. However, I just tried it on a Solaris box and it worked flawlessly. The only thing I had to change was adding the $ sign in front of the "normal" variable. Do you have another typo somewhere else in your script?

    #!/bin/bash -

    bold="\033[1m"
    normal="\033[0m"
    greentext="\033[32m"

    echo -e $bold "Quick System report for "$greentext"$HOSTNAME"$normal


    Question: What does the -e option for echo do?
    Goals for 2018:
    Certs: RHCSA, LFCS: Ubuntu, CNCF CKA, CNCF CKAD | AWS Certified DevOps Engineer, AWS Solutions Architect Pro, AWS Certified Security Specialist, GCP Professional Cloud Architect
    Learn: Terraform, Kubernetes, Prometheus & Golang | Improve: Docker, Python Programming
    To-do | In Progress | Completed
  • Options
    ally_ukally_uk Member Posts: 1,145 ■■■■□□□□□□
    I will give it a shot :) and will report back it was kinda late when I was tinkering.

    The -e option for echo enables interpretation of backslash characters, Maybe somebody can explain that part a bit better im also
    a noob when it comes to scripting.The example code I posted originally is from a tutorial video I am following unless the tutor is doing
    things weird and is making typos with code hence why it didnt work initially.
    Microsoft's strategy to conquer the I.T industry

    " Embrace, evolve, extinguish "
  • Options
    DoubleNNsDoubleNNs Member Posts: 2,015 ■■■■■□□□□□
    Got it to work?
    Goals for 2018:
    Certs: RHCSA, LFCS: Ubuntu, CNCF CKA, CNCF CKAD | AWS Certified DevOps Engineer, AWS Solutions Architect Pro, AWS Certified Security Specialist, GCP Professional Cloud Architect
    Learn: Terraform, Kubernetes, Prometheus & Golang | Improve: Docker, Python Programming
    To-do | In Progress | Completed
  • Options
    ally_ukally_uk Member Posts: 1,145 ■■■■□□□□□□
    No it doesn't work I think it may be a virtual machine issue. Can you try running the code virtually and see what happens?
    Microsoft's strategy to conquer the I.T industry

    " Embrace, evolve, extinguish "
  • Options
    DoubleNNsDoubleNNs Member Posts: 2,015 ■■■■■□□□□□
    Your VM should function just like a regular system.

    What distro are you using? Did you try copying and pasting my script above directly?

    Trytyping the following commands on your VM and see whether they work:

    $ tput bold
    $ tput sgr0
    Goals for 2018:
    Certs: RHCSA, LFCS: Ubuntu, CNCF CKA, CNCF CKAD | AWS Certified DevOps Engineer, AWS Solutions Architect Pro, AWS Certified Security Specialist, GCP Professional Cloud Architect
    Learn: Terraform, Kubernetes, Prometheus & Golang | Improve: Docker, Python Programming
    To-do | In Progress | Completed
  • Options
    brownwrapbrownwrap Member Posts: 549
    Am I missing something. I have CenTOS on my notebook:

    [gcr@wireless-host-22-151 ~]$ vi test-script
    [gcr@wireless-host-22-151 ~]$ chmod +x test-script
    [gcr@wireless-host-22-151 ~]$ ./test-script
    Quick System report for localhost.localdomain
    [gcr@wireless-host-22-151 ~]$

    I copied your code into test-script and it ran. Doesn't show here, but 'Quick System report' came out in bold, the rest in green
  • Options
    ally_ukally_uk Member Posts: 1,145 ■■■■□□□□□□
    Yeah sorry about the delay guys, I finally got it to work for some reason if you run Centos virtually without a gui it doesn't invoke the bold setting

    I have since ran it on a desktop and it works fine, Probably works if you remote in the virtual machine with SSH but havent gone that far.
    Microsoft's strategy to conquer the I.T industry

    " Embrace, evolve, extinguish "
Sign In or Register to comment.