Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what language uses "fi"

Tags:

shell

Saw this script and I am trying to figure out what language is used... it's almost like C but I noticed the fi as a way to close the nested if.

function prompt () {
if [ "$noprompt" ] && [ "$#" = "1" ]; then
    if [ "$1" = "yes" ]; then
        echo "DEFAULT: yes"
        return 0
    else
        echo "DEFAULT: no"
        return 1
    fi
fi

while true; do
    echo "Enter \"yes\" or \"no\": "
    read response
    case $response
    in
        Y*) return 0 ;;
        y*) return 0 ;;
        N*) return 1 ;;
        n*) return 1 ;;
        *)
    esac
done
}
like image 736
netrox Avatar asked Jun 10 '11 17:06

netrox


People also ask

Which programming language uses Fi?

fi are used by Unix/Linux shells in shell programming, This is an if statement.

What is Fi in language?

fi statement is the fundamental control statement that allows Shell to make decisions and execute statements conditionally.

Why does bash use fi?

The fi is to close the if-block in the y) case statement and the ;; is used to end the y) case.

What does fi mean in Python?

fi fi. If statement and else statement could be nested in bash. The keyword “fi” indicates the end of the inner if statement and all if statement should end with the keyword “fi”.


1 Answers

The piece of code is Unix shell. But the answer to the question

what language uses “fi”

is a bit longer. The usage of mirrored words, like if and fi or case and esac comes from Algol, for a nice summary see comparison of languages. It was Stephen Bourne who carried this from Algol to the Unix shell, he worked first on Algol, later on sh and adb of the early Unix systems. He favored this syntax so much that even the C code he wrote for sh and adb looks like Algol thanks to a bunch of preprocessor macros. The curious can have a look at the 2.11BSD source code of source code of sh or adb. It compiles as C after all. So even in C one can find FI when going back a long way in history.

like image 183
wfjm Avatar answered Nov 01 '22 20:11

wfjm