One for the Guild of Linux ( Bash related question )

ally_ukally_uk Posts: 1,146Member ■■■■□□□□□□
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

  • DoubleNNsDoubleNNs Posts: 2,013Member ■■■■■□□□□□
    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
  • ally_ukally_uk Posts: 1,146Member ■■■■□□□□□□
    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 "
  • DoubleNNsDoubleNNs Posts: 2,013Member ■■■■■□□□□□
    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
  • ally_ukally_uk Posts: 1,146Member ■■■■□□□□□□
    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 "
  • DoubleNNsDoubleNNs Posts: 2,013Member ■■■■■□□□□□
    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
  • brownwrapbrownwrap Posts: 549Member
    Am I missing something. I have CenTOS on my notebook:

    [[email protected] ~]$ vi test-script
    [[email protected] ~]$ chmod +x test-script
    [[email protected] ~]$ ./test-script
    Quick System report for localhost.localdomain
    [[email protected] ~]$

    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
  • ally_ukally_uk Posts: 1,146Member ■■■■□□□□□□
    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.