多姿多彩的HelloWorld

资料来源(视频【翻墙】):Hello Worlds – Linux – Different Languages

以下分别是C, C++, Python, Perl, Java, HTML/Javascript, Haskell, and Shell (plus R)的“Hello Wolrd”实现。
注:html和Javascript的显示有问题。所有的代码可以下载helloworld

  • C

touch hello.c
vim hello.c

1
2
3
4
5
6
7
#include 
 
int main()
{
	printf("Hello, World!n"); 
	return 0; 
}

gcc hello.c -o hello-C
./hello-C

  • C++

touch hello.cpp
vim hello.cpp

1
2
3
4
5
6
7
#include 
 
int main()
{
	std::cout  << "Hello, World!"  << std::endl; 
	return 0; 
}

g++ hello.cpp -o hello-C++
./hello-C++

  • Python

touch hello-Python
vim hello-Python

1
2
3
4
5
6
7
#!/usr/bin/env python
 
def main():
	print 'Hello, World!'
 
if __name__ == '__main__':
	main()

chmod +x hello-Python
./hello-Python

  • Perl

touch hello-Perl
vim hello-Perl

1
2
3
#!/usr/bin/env perl
 
print "Hello, World!n";

chmod +x hello-Perl
./hello-Perl

  • java

touch Hello.java
vim Hello.java

1
2
3
4
5
public class Hello{
	public static void main(String[] args){
		System.out.println("Hello, World!");
	}
}

javac Hello.java
java Hello

  • html

touch hello.html
vim hello.html

1
...

google-chrome hello.html

  • Javascript

cp hello.html hello.Javascript
vim hello.Javascript

1
...

google-chrome hello.Javascript

  • Haskell

touch hello.hs
vim hello.hs

1
main = putStrLn "Hello, World!"

ghc hello.hs -o hello-Haskell
./hello-Haskell

  • Shell

touch hello.sh
vim hello.sh

1
echo "Hello, World!";

chmod +x hello.sh
./hello.sh

  • R

touch hello.R
vim hello.R

1
cat("Hello, World!n")

Rscript hello.R