Skip to content

Instantly share code, notes, and snippets.

@goose-ws
Last active February 24, 2025 11:23
Show Gist options
  • Save goose-ws/1df1b680b6c463076574b62d08e52873 to your computer and use it in GitHub Desktop.
Save goose-ws/1df1b680b6c463076574b62d08e52873 to your computer and use it in GitHub Desktop.
They say if it's more than 100 lines, you should write it in a real language, instead of bash. I say, with enough semicolons, any bash script can be a one line bash script.
while IFS= read -r line; do while [[ "${line:0:1}" =~ ($'\t'| ) ]]; do line="${line:1}"; done; if [[ "${line:0:1}" == "#" || -z "${line}" ]]; then continue; fi; if [[ "$line" =~ [^\\#][[:space:]]+# ]]; then line="${line% #*}"; fi; if [[ -n "${line}" ]]; then [[ "$line" =~ \b(do|then)$ ]] && output+="$line " || output+="$line; "; fi; done < "${1}"; output="${output//;;/;}"; echo "${output#;}"
@goose-ws
Copy link
Author

I made it a one liner, as poetic justice demands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment