Your bash++ post inspired me to whip up a fun little one liner. I say, with enough semicolons, any bash script can be a one line bash script! May I present, a bash one line script that will turn...
Your bash++ post inspired me to whip up a fun little one liner.
If you are writing a script that is more than 100 lines long, or that uses non-straightforward control flow logic, you should rewrite it in a more structured language now.
I say, with enough semicolons, any bash script can be a one line bash script! May I present, a bash one line script that will turn any other bash script into a one line 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#;}"
Wrote it in standard markdown to make sure it worked, then manually combined it to a single line because I have a smooth brain and didn't think to use it on itself. The readable/original: while...
Wrote it in standard markdown to make sure it worked, then manually combined it to a single line because I have a smooth brain and didn't think to use it on itself.
The readable/original:
while IFS= read -r line; do
# Strip leading tabs and white space
while [[ "${line:0:1}" =~ ($'\t'| ) ]]; do
line="${line:1}"
done
# If it's a comment or blank line, skip it
if [[ "${line:0:1}" == "#" || -z "${line}" ]]; then
continue
fi
# If it has a trailing comment, remove the trailing comment
if [[ "$line" =~ [^\\#][[:space:]]+# ]]; then
line="${line% #*}"
fi
# If we still do not have a blank line, combine the output
if [[ -n "${line}" ]]; then
[[ "$line" =~ \b(do|then)$ ]] && output+="$line " || output+="$line; "
fi
done < "${1}"
# Remove redundant semicolons
output="${output//;;/;}"
# Trim any accidental leading semicolons
echo "${output#;}
I'll fuckin do it again
Your bash++ post inspired me to whip up a fun little one liner.
I say, with enough semicolons, any bash script can be a one line bash script! May I present, a bash one line script that will turn any other bash script into a one line script:
Did you write it in 1 line originally, or in multiple lines and then run it on its own code to make it single line?
Wrote it in standard markdown to make sure it worked, then manually combined it to a single line because I have a smooth brain and didn't think to use it on itself.
The readable/original:
Never much cared for or used heredoc's myself, so didn't account for them. I guess I should say, turn most other bash scripts into a one line script.
Ah, but have you considered matrix text underneath a water effect shader in space in your terminal while you write your OpenGL functions?
This is a good bit, by all means never stop
Disgusting, thanks for posting!
Where do you keep finding these?!
It’s all interesting, and (unfortunately) still about Bash all the same. 😭
Ew.
If this were IRC, this is where you would
/nick hungarianbashKeep up the good work.