Last active
August 1, 2025 03:15
-
-
Save mrclay/36149a3a0d068ca2a2dc8b784a262135 to your computer and use it in GitHub Desktop.
Build up an inline string in bash with clearer whitespace handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Strategy 1: trim whitespace from heredoc: | |
| curl "$(tr -d '[:space:]' <<EOD | |
| http://www.example.com/articles/technology/2024/07/10 | |
| /this-is-an-example-of-a-very-long-article-title-with-lots | |
| ?query=example&page=2 | |
| #section3 | |
| EOD | |
| )" | |
| # Strategy 2: build up temp var in subprocess: | |
| # Below "a" is built up in the subprocess and does not | |
| # clobber $a in the current environment. | |
| curl "$( \ | |
| a='http://www.example.com/articles/technology/2024/07/10'; \ | |
| a+='/this-is-an-example-of-a-very-long-article-title-with-lots'; \ | |
| a+='?query=example&page=2'; \ | |
| a+='#section3'; \ | |
| echo ${a})" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment