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!

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

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

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 2 comments… read them below or add one }

1 BWIRE KENNEDY JUMA May 29, 2012 at 12:18 pm

Please show me how to write a progam in Pascal that calculates the average mark of a student given 5 exam marks and output the average.

2 Benjamin Olawale June 16, 2012 at 3:56 am

Write a Pascal program to assign grades to scores of 100 students. The grading system is given as 70-100= A 60-69= B 50-59= C 45-49= D 40-44= E 0-39= F

Leave a Comment

Previous post:

Next post: