I’ve seen many examples with multiple conditions related to each other, but there are 2 different unrelated conditions where the second one only should happen if the first one is true.
How can I get the following nicely organised and in 1 line?
funtion1
if [[ $valueX == 2 ]]; then
funtion2
if [[ $valueY -gt 16 ]]; then
sleep $valueZ
fi
fi
You can have it nicely organized, or you can have it in one line.
I’d say what you have now is already nicely organized. I don’t think there’s any way to reorganize it in fewer lines without making it less legible.
(If the
funtion2weren’t there, you could combine the two conditions.)If you insist on putting that entire chunk of code on line line, you can do it simply by joining the lines and adding semicolons, like this:
But as I said, I don’t think anyone would call this “nicely organized”; it’s more difficult to read, and to maintain, than the original multi-line nicely indented version.
Note that the
[[syntax is specific to bash; ash doesn’t support it.(Oh, and you’ve misspelled “function”.)