Pascal Hello World Example: How To Write, Compile and Execute Pascal Program on Unix OS

by Ramesh Natarajan on October 9, 2009

Question: I would like to understand the basics of how to write and execute a pascal program on Linux OS. Can you explain it with a simple example?

Answer: In this article, let us review very quickly how to write a basic Hello World pascal program and execute *.p or *.pas program on Linux or Unix OS.

1. Write a Hello World Pascal Program

Create the helloworld.p program using a Vim editor as shown below.

$ vim HelloWorld.p

Program HelloWorld(output);
begin
  writeln('Hello, world!');
end.

2. Make sure pascal compiler is installed on your system

Make sure pascal compiler is installed on your system as shown below.

$ whereis pc
pc: /usr/bin/pc /usr/share/man/man1/pc.1.gz

$ which pc
/usr/bin/pc

Installing pascal compiler

If you don’t have pascal compiler, install it as shown below.

$ sudo apt-get install fp-compiler

3. Compile the pascal program.

Compile the HelloWorld.p which will create the HelloWorld executable.

$ pc HelloWorld.p
Free Pascal Compiler version 2.2.2-8 [2009/01/08] for i386
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Linux for i386
Compiling HelloWorld.p
Linking HelloWorld
4 lines compiled, 0.1 sec 

$ ls
HelloWorld*  HelloWorld.o  HelloWorld.p

4. Execute the pascal program.

Execute by mentioning the program name.

$ ./HelloWorld
Hello, world!
Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

If you enjoyed this article, you might also like..

  1. How To Write, Compile and Execute C Program on Unix OS [With Hello World Example]
  2. How To Write, Compile and Execute C++ Program on Unix OS (With Hello World Example)
  3. Haskell Hello World Example: How To Write, Compile and Execute Haskell Program on Linux OS
  4. Cobol Hello World Example: How To Write, Compile and Execute Cobol Program on Linux OS
  5. Fortran Hello World Example: How To Write and Execute Fortran Program on Linux OS
  

Vim 101 Hacks Book

Leave a Comment

Previous post:

Next post: