5

Which is the shortest way to get the variable $DISTRIB_CODENAME from /etc/lsb-release?

I want to make this somewhat shorter:

$ sudo add-apt-repository \
  "deb http://some-repo/ubuntu $(grep CODENAME lsb-release |sed s/^.*=//g) main"
slm
  • 363,520
  • 117
  • 767
  • 871
rubo77
  • 27,777
  • 43
  • 130
  • 199

2 Answers2

7

You can source that file in bash (or any Bourne-like shell) to set them as shell variables:

source /etc/lsb-release
sudo add-apt-repository "deb http://some-repo/ubuntu $DISTRIB_CODENAME main"
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Anthon
  • 78,313
  • 42
  • 165
  • 222
7

The command lsb-release has an option to display codename according to the distribution release:

apt-get install lsb-release
lsb_release -c -s

So you can try to rewrite it like this:

sudo add-apt-repository "deb http://some-repo/ubuntu $(lsb_release -c -s) main"

For details, check man lsb_release.

rubo77
  • 27,777
  • 43
  • 130
  • 199
dsmsk80
  • 3,038
  • 1
  • 15
  • 20