Thank you for showing how to avoid variable expansion! 👍 That often trips me up.
@__gazal__9 ай бұрын
Thanks!
@NickJanetakis9 ай бұрын
Anytime, thanks a lot for the tip, I really appreciate it!
@ssd60109 ай бұрын
I love your shell scripts contents
@pavelzadorski5 ай бұрын
Great content, thanks! Have you stumbled upon one more use-case: To have a self-contained script creating a file with JSON values interpolated using shell variables. You explained great how to assign a variable and how to save a file. Thanks again! :) What I found not obvious is how to make use of both, so that JSON indentation won't clash with script's own indentation. I found your video on a quest for the following goal: - A here-doc is assigned to a variable outside of bash function (with the heredoc ingesting other shell variables). - A here-doc with variable expansions gets saved to a file inside of a function (while preserving JSON indentation). - Just echoing multi-line variable has its own peculiarities, so the possible solution might be usage of cat/tee and eval/envsubst.
@NickJanetakis5 ай бұрын
Hi, if you find yourself fighting indentation you can always pipe it to jq to format the JSON however you see fit. Would that work?
@pavelzadorski5 ай бұрын
Hey @NickJanetakis, thanks for the response! Yesterday, I encountered a similar situation with KQL. This is a broader question. Using jq for formatting at runtime is more of a workaround. Instead, having a script with multi-line values enriched via shell variables would be best for readability. The simplest approach I found was using a function that employs cat to direct a heredoc into a file, which another function then reads. My initial aim was to store a multi-line variable (e.g., a lengthy KQL query) separately from the main function. Then we could use multi-line values with proper parameter substitutions directly (e.g. az graph), without creation of yet another temporary file :)
@nnutipa9 ай бұрын
Thanks for the video. Why didn't you mention
@NickJanetakis9 ай бұрын
I have an awareness of it but it has never come up in anything I've done. It's only for stripping leading tab characters right? Most set ups and code formatting tools will convert tabs to spaces. Am I missing something?
@nnutipa9 ай бұрын
@@NickJanetakis Yes, you must use tabs, but I am not sure about tab conversion to spaces. Afaik, if you don't want this to happen you can turn this functionality off in almost every text editor.
@NickJanetakis9 ай бұрын
@@nnutipa Right, I mean in almost all cases I've seen while working for and with folks, there has been a general census to replace tabs with spaces at the code editor level and it's also sometimes enforced by code formatting tools for specific languages. The only exception has been for files that require hard tabs like a Makefile.