← 返回命令列表

Linux command

fi 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

End if statement

if [ condition ]; then commands; fi

If-else structure

if [ condition ]; then commands; else other; fi

Nested if with

if [ cond1 ]; then cmd1; elif [ cond2 ]; then cmd2; fi

说明

fi is a shell keyword that closes an if conditional block. It's part of the shell's control flow syntax, marking where conditional execution ends. The if/then/fi structure evaluates conditions and executes code blocks based on exit statuses. Conditions can use test commands, [ ], or any command's exit status. fi must appear for every if, matching them like parentheses.

参数

if
Begin conditional block.
then
Commands to execute if condition is true.
elif
Else-if for additional conditions.
else
Commands if no conditions matched.
fi
End of if block (if spelled backward).

FAQ

What is the fi command used for?

fi is a shell keyword that closes an if conditional block. It's part of the shell's control flow syntax, marking where conditional execution ends. The if/then/fi structure evaluates conditions and executes code blocks based on exit statuses. Conditions can use test commands, [ ], or any command's exit status. fi must appear for every if, matching them like parentheses.

How do I run a basic fi example?

Run `if [ condition ]; then commands; fi` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does if do in fi?

Begin conditional block.