≡ Menu

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

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);
  writeln('Hello, world!');

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

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!
Add your comment

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

Comments on this entry are closed.

  • BWIRE KENNEDY JUMA May 29, 2012, 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.

  • Benjamin Olawale June 16, 2012, 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