A Trick about Shell Programming and C Programming: Always Add a New Line at the End of Your Code

[Note] This message was posted on Forum 60-256 at Ataraxis (BBS ofComputer Sicence).

Most of us know that we should add a new (empty) line at the end of our C code. In the same way we need to add a new (empty) line in Shell Programming.

In C, if u didn't add a new line, you can't compile your C code. But in Shell programming, generally you can run your shell script correctly, but sometimes ......

Suppose we have a piece of shell script named "test.sh":

#!/bin/csh -f

if ("$1" == "a") then
echo "equal"
else
echo "not equal"
endif
# Here is a new line at the end of the script



when you use commands "./test.sh a" and "./test.sh b" to test the script, both of them work fine.

But if you change the script to:

#!/bin/csh -f

if ("$1" == "a") then
echo "equal"
else
echo "not equal"
endif # No new line at the end of the script



when you use command "./test.sh b", it runs fine. But if you use command "./test.sh a", some problem happens ......

类别:

添加新评论

友情提醒:您的言论自由在本站会得到充分保证;不过,由于广告留言等猖獗,因此本站的内容过滤系统有可能会暂时屏蔽您新发的留言或评论。不便之处,希望理解。