thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

GNU sed: follow symlinks

• 80 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

Previously.

Today we will upgrade Terraform in the entire codebase:

shell
fd -e tf | ifne xargs gsed -i -e 's/required_version = "~> 1.6.6/required_version = "~> 1.10.0/g'

Easy, right?

During code review, a teammate has pointed out that I replaced many symlinks. How?! This was completely unintended!

Eventually I figured out the reason. From sed(1):

--follow-symlinks

follow symlinks when processing in place

It turns out it is necessary to pass --follow-symlinks to preserve symlinks when using -i with GNU sed.