2

I am writing a bash script which has a subtask of printing the Ubuntu name on which the system is running. I did:

ubuntu_ver=$(lsb_release -a | grep Description | cut -d":" -f2)
echo $ubuntu_ver

Ubuntu 12.04 LTS got stored in variable ubuntu_ver but and additional line got printed on the top. The output was:

No LSB modules are available.
Ubuntu 12.04.4 LTS

How to prevent the 'No LSB modules...' from getting printed?
In fact this line gets printed whenever I try to store something in a variable from the command 'lsb_release -a'.

nishantsingh
  • 4,537
  • 5
  • 25
  • 51

2 Answers2

4

In fact this line gets printed whenever I try to store something in a variable from the command lsb_release -a

This suggests that the offending line is actually an error message. Discard it:

ubuntu_ver=$(lsb_release -a 2>/dev/null | grep Description | cut -d":" -f2)
devnull
  • 118,548
  • 33
  • 236
  • 227
3

-a includes -v which returns a list of lsb modules, which is why you get the message that none are found.

Also I'd suggest just asking for the description (-d) and omitting the header (-s):

ubuntu_ver=$(lsb_release -ds)
echo $ubuntu_ver
plundra
  • 18,542
  • 3
  • 33
  • 27