0

In Wikipedia there are two relevant articles about the term "Flip-flop":

I think that there is a formal-logic common denominator between the two issues.

I am an amateur sysadmin with some tiny knowledge in Bash which does some system administration only for myself; I have no intention to one day become an electronics engineer, firmware developer or anything like that, but I do want to learn about the general meaning of Flip-flops (electronics/programming) via Bash if this is possible via a primal simple example for newcomers to learn about the term.

If indeed there is a formal-logic common denominator between Flip-flops in electronics and Flip-flops in programming, what would be a simple shell (Bash) example?

5
  • 1
    Aside from sharing the name, I don't think those two concepts have anything to do with one another. – Andy Dalton Feb 28 at 15:39
  • I'm not sure what you're looking for here. Both meanings of flip-flop are things that flip from one state to another in response to some event. E.g. an SR-flip-flop flips to 1 is the S signal is asserted, and flops to 0 if the R signal is asserted; and the Ruby operator flips to "true" when the first condition is met, and flops back to "false" when the second condition is met. To "flip" something means to turn it over, and flop probably is there just because the combination sounds pleasing. Maybe. The meaning is also similar to this: en.wikipedia.org/wiki/Flip-flop_(politics) – ilkkachu Feb 28 at 15:58
  • @ilkkachu I'm not sure what you're looking for here. Both meanings of flip-flop are things that flip from one state to another in response to some event thanks for clarifying that ! and btw, also thanks for the nice laugh from the politics article link (that was a surprising common denominator for me to discover). – timesharer Feb 28 at 18:17
  • If flip flop is just a fancy term for "change" (from mode X to mode Y) than I think that is a valid answer. – timesharer Feb 28 at 18:18
  • @timesharer, maybe like changing between two states (or opinions), not just any change? Or something like that. I think it's just one of those phrases that are used in particular contexts and seeing it in another context might require some explanation. – ilkkachu Feb 28 at 18:48
0

Aside from sharing the name, I don't think those two concepts have anything to do with one another.

But if you're looking for something in bash that behaves like this Ruby example from the Wikipedia article you linked:

(1..10).each do |x|
  puts x if (x == 4 .. x == 6)
end

A version of that in bash is:

#!/bin/bash

do_print="false"
for ((i = 1; i <= 10; ++i)); do
    if [[ ${i} -eq 4 ]]; then
        do_print="true"
    fi

    if [[ "${do_print}" == "true" ]]; then
        echo "${i}"
    fi

    if [[ ${i} -eq 6 ]]; then
        do_print="false"
    fi
done

The do_print variable "flips" on when i=4 and "flops" off when i=6. Bash doesn't have the syntactic sugar to do that the way Ruby does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.