From my understanding, it is possible to convert any bash script into a single line by inserting semi-colons at the end of each line of code and removing the new-line.
Firstly - am I correct in this assumption?
Secondly, are there any tools/scripts that do this function automatically?
Note: I do not want to change any command in the Bash script, not optimize to change to pipe-based commands, nothing. Keep it as is, and be able to run it. This is a unique situation in which I must have it in a single line no matter what.
I have tried looking online, over Google or GitHub, but was left empty-handed.
am I correct in this assumption?
No. Not every newline can be replaced by ;
. Counterexample:
if true; then
echo 1
fi
cmd1 &&
# comment
cmd2
can be converted to:
if true; then echo 1; fi; cmd1 && cmd2
There is no semicolon after then
. There is no semicolon after &&
. Additionally comments and empty lines.
are there any tools/scripts that do this function automatically?
I am not aware of any. Additionally, I see no value in doing that.
Any script can be converted to a single line by using base64 and then decoding.
oneline=$(base64 -w0 <script.sh)
base64 -d <<<"$oneline" | bash