On macOS, one can use pbcopy

echo "this is what I want to copy to the system clipboard" | pbcopy

This copies the piped content into the system clipboard, so that it can be pasted with ctrl+V shortcut.

On Ubuntu, this can be accomplished with xclip but with an extra option:

echo "this is what I want to copy to the system clipboard" | xclip -sel clip

I find it a bit annoying to specify the option every time I use it, so I added an alias into my .bashrc file

echo 'alias xclip="xclip -sel clip"' >> ~/.bashrc