The overall command echo "..." | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null writes some content into the /etc/apt/sources.list.d/ros2.list file. It uses this structure because typically you need to be root to create or modify files in /etc/apt/sources.list.d, and echo ... | sudo tee ... is a common way to do avoid permission errors that arise with sudo echo ... > ....
Now for the content being written:
deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main
This uses command substitution $(…) twice, where the entirety of $(…) is replaced with output of the commands inside it.
- The first use is for
dpkg --print-architecture, which prints the default architecture of your Ubuntu installation. So this part will be replaced with something like amd64, arm64, etc.
- The second use is
. /etc/os-release && echo $UBUNTU_CODENAME. This is a way to print the codename associated with an Ubuntu release (focal, jammy, noble, etc.). The /etc/os-release contains various variables in a shell-friendly format with details of the OS, like OS family, version, code name, etc.
All told, the content will reduce to something like:
deb [arch=amd64 signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu jammy main
This is a sources.list entry which is restricted to the default architecture (so if you're on amd64 and also added i386, this repo will only be used for amd64), and uses a specific signing key.
It's a fairly normal sources.list entry. But the whole point of the command is that it will affect your PC. Adding a software source is a significant change. If tomorrow this repo adds packages like bash or gnome-shell, those might well end up overriding the corresponding packages in the Ubuntu repos and getting installed on your system. Not likely, but it could happen.
amd64, for example, will be http://packages.ros.org/ros2/ubuntu/dists/jammy/main/binary-amd64/Packages – muru Jul 09 '24 at 10:47