Basic scripting on linux

This time I’m taking a look at how to run some basic hello world scripts on linux. I’ll showcase Python, Java and Bash. I’m using my HP EliteBook 2570p as a local computer and I’m running Xubuntu 16.04.3. This is an assignment for a Linux server course taught by Tero Karvinen.

Using Python

Python is a rather simple language of which I had some previous knowledge of, so I decided to test it out first. Python comes pre-installed on Ubuntu so it comes with Xubuntu as well. To see if you have Python on your computer, you can use the following commands:

whereis python
which python

These show you the program folder. If you don’t have it yet, you can install it with “sudo apt-get install python3“.

To write a Python script, you can use nano. I used the command “nano hei.py” to create the script. Inside I wrote a simple print command:

python1

To execute the script in terminal type in “python3 filename“. I used the command “python3 hei.py“:

python2

Using Java

My second language was Java. I decided to make a short script that prints out “Hello World”. I started by installing JDK (Java Development Kit): “sudo apt-get install default-jdk“.

Then I created a Java file with nano: “nano hei.java

java1

I had to compile the file so I did it with “javac hei.java“. There was no visual feedback, which typically means that everything went according to plan. After this I executed the file with “java hei” (notice without the .java) and it worked fine! Although the terminal continues operating on the same line for an unknown reason.

java2

Using Bash

My final language was Bash. The environment comes pre-installed on Ubuntu, but I could’ve installed it as well with “sudo apt-get install bash“. I created a Bash script with “nano hei.sh“:

bash1

To execute a Bash script you need to use the “sh” command. Here I typed “sh hei.sh“:

bash2

Works great!

 

Sources:

http://terokarvinen.com/2017/aikataulu-%E2%80%93-linux-palvelimet-ict4tn021-7-ti-ja-6-to-alkukevat-2018-5-op – The course I’m attending

https://valtteripuhakka.wordpress.com/2017/10/10/hello-world-javalla-pythonilla-ja-clla/ – Help with Java

https://mikkoknutas.wordpress.com/2017/10/08/h6-hei-maailman-asennus-ja-suoritus-kolmella-eri-kielella/ – Help with Bash

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s