Browse Source

H6: Update text syntax

master
Pekka Helenius 5 years ago
committed by GitHub
parent
commit
3c4d986b74
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 16 deletions
  1. +26
    -16
      exercises/h6.md

+ 26
- 16
exercises/h6.md View File

@ -11,7 +11,7 @@ This exercise is a part of [Linux servers (ICT4TN021, spring 2018) // Linux-palv
**Answer:** **Answer:**
Let's write "Hello World" in the following three languages: perl, python 3 and C. Let's install needed development tools:
Let's write "Hello World" in the following three languages: `perl`, `python 3` and `C`. We need to install required development tools:
``` ```
sudo apt-get -y install perl python gcc sudo apt-get -y install perl python gcc
@ -19,23 +19,23 @@ sudo apt-get -y install perl python gcc
(GCC = [Gnu Compiler Collection](https://gcc.gnu.org/) + [Wikipedia](https://en.wikipedia.org/wiki/GNU_Compiler_Collection)) (GCC = [Gnu Compiler Collection](https://gcc.gnu.org/) + [Wikipedia](https://en.wikipedia.org/wiki/GNU_Compiler_Collection))
Let's write the codes into a subfolder _hello-world_ in user's home dir:
Let's write the codes into a subfolder `hello-world` in user's home dir:
``` ```
[newuser@goauldhost: ~ ]$ mkdir ~/hello-world [newuser@goauldhost: ~ ]$ mkdir ~/hello-world
[newuser@goauldhost: ~ ]$ cd hello-world/ [newuser@goauldhost: ~ ]$ cd hello-world/
[newuser@goauldhost: hello-world ]$ touch {hello.py,hello.pl,hello.c}
[newuser@goauldhost: hello-world ]$ touch hello{.c,.py,.pl}
``` ```
- hello.py = "Hello World" written in Python 3
- `hello.py` = "Hello World" written in Python 3
- hello.pl = "Hello World" written in Perl
- `hello.pl` = "Hello World" written in Perl
- hello.c = "Hello World" written in C
- `hello.c` = "Hello World" written in C
Hello World program written in three languages (nano editor used): Hello World program written in three languages (nano editor used):
**Perl (hello.pl):**
### Perl (hello.pl)
``` ```
#!/usr/bin/env perl #!/usr/bin/env perl
@ -50,7 +50,7 @@ print "Hello World!\n";
``` ```
**Python (hello.py):**
### Python 3 (hello.py)
``` ```
#!/usr/bin/env python3 #!/usr/bin/env python3
@ -61,17 +61,17 @@ print("Hello World!");
``` ```
**NOTE!** Pay attention when referring to python executable. On some Linux distributions, python refers to python2, and on some, python refers to python3. Practices differ. It can be safer to use 'python3' or 'python2' instead of just 'python'.
**NOTE!** Pay attention when referring to python executable. On some Linux distributions, python still refers to `python2`, and on some, python refers to `python3`. Practices differ. It can be safer to use 'python3' or 'python2' instead of just 'python' if not sure.
In a simple program like "Hello world" this python issue doesn't really matter but if any python libraries are imported into the code, you must know which python environment to use, Python 2 or Python 3.
In a simple program like "Hello world" this python issue doesn't really matter. However, if any python libraries are imported into the code, you must know which python environment to use, Python 2 or Python 3.
**C (hello.c):**
### C (hello.c)
``` ```
// Include Standard Input Output Library (stdio.h core library included in)
// Include Standard Input Output Library
#include <stdio.h> #include <stdio.h>
// Declare main function for the program. Int for returning a integer
// Declare main function for the program. int type for returning a integer
int main() int main()
{ {
// Print Hello World! (stdout in CLI) // Print Hello World! (stdout in CLI)
@ -82,19 +82,27 @@ int main()
} }
``` ```
hello.c requires compiling from source code to executable binary file. Therefore, we compile the source code with the following command in _hello-world_ folder:
`hello.c` requires compiling from source code to executable binary file. Therefore, we compile the source code with the following command in `hello-world` folder:
``` ```
gcc -o hello hello.c gcc -o hello hello.c
``` ```
after which our 'binary' can be executed with
after which our `hello` binary can be executed with
``` ```
~/hello-world/hello ~/hello-world/hello
``` ```
All programs give stdout/output string "Hello World!" in our shell environment:
**NOTE:** You can check file details by issuing the following command:
```
file ~/hello-world/hello
hello: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=8e76492bc5ce6c65df8ec5ce7be42645fae2ab70, not stripped
```
All programs give output string "Hello World!" (stdout data stream) in our shell environment:
``` ```
[newuser@goauldhost: hello-world ]$ pwd [newuser@goauldhost: hello-world ]$ pwd
@ -116,6 +124,8 @@ This could have been very interesting assignment to work out. Unfortunately, my
![winecfg-update](https://i.imgur.com/SihmPUA.jpg) ![winecfg-update](https://i.imgur.com/SihmPUA.jpg)
See: [Fincer/winecfg_patch](https://github.com/Fincer/winecfg_patch)
Some Python and bash based program-related scripts and code updates are available here: Some Python and bash based program-related scripts and code updates are available here:
- [PlayOnLinux patches](https://github.com/Fincer/linux-patches-and-scripts/tree/master/playonlinux). - [PlayOnLinux patches](https://github.com/Fincer/linux-patches-and-scripts/tree/master/playonlinux).


Loading…
Cancel
Save