本文介绍了Bash的约定,如果;然后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个网页:

它提到的,如果支架再公约这就需要分号后的空间使用情况:

Does anyone know where is this coming from and if this is needed at all by certain shells?

解决方案

This has become the style in the last few years:

if [ -x "$filename" ]; then
   echo "hi"
fi

However, back when dinosaurs like Burroughs and Sperry Rand ruled the earth, I learned to write if statements like this:

if [ -x "$filename" ]
then
    echo "hi"
fi

Then, you don't even need a semicolon.

The new style with then on the same line as the if started in order to emulate the way C and other programming languages did their if statements:

if (! strcmp("foo", "bar")) {
   printf "Strings equal\n";
}

These programming languages put the opening curly brace on the same line as the if.

这篇关于Bash的约定,如果;然后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:56
查看更多