Skip to content

Commit 2a3eb9c

Browse files
committed
Python Shebang: Add missing files
1 parent b5254fc commit 2a3eb9c

File tree

5 files changed

+262
-0
lines changed

5 files changed

+262
-0
lines changed

python-shebang/README.md

Lines changed: 247 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
# Should You Put the Unix Shebang (#!) in Python Scripts?
2+
3+
This folder holds the code for the Real Python Should You Put the Unix Shebang (#!) in Python Scripts? tutorial.
4+
5+
## Sample Scripts
6+
7+
### Python
8+
9+
Command:
10+
11+
```shell
12+
$ ./hello.py
13+
Hello from Python!
14+
```
15+
16+
Source:
17+
18+
```python
19+
#!/usr/bin/env python
20+
21+
print("Hello from Python!")
22+
```
23+
24+
### Perl
25+
26+
Command:
27+
28+
```shell
29+
$ ./hello.pl
30+
Hello from Perl!
31+
```
32+
33+
Source:
34+
35+
```perl
36+
#!/usr/bin/env perl
37+
38+
print "Hello from Perl!\n";
39+
```
40+
41+
### JavaScript
42+
43+
Command:
44+
45+
```shell
46+
$ ./hello.js
47+
Hello from JavaScript!
48+
```
49+
50+
Source:
51+
52+
```javascript
53+
#!/usr/bin/env node
54+
55+
console.log("Hello from JavaScript!")
56+
```
57+
58+
### Java
59+
60+
Command:
61+
62+
```shell
63+
$ ./hello.j
64+
Hello from Java!
65+
```
66+
67+
Source:
68+
69+
```java
70+
#!/usr/bin/env -S java --source 11
71+
public class Hello {
72+
public static void main(String[] args) {
73+
System.out.println("Hello from Java!");
74+
}
75+
}
76+
```
77+
78+
## Custom Interpreter
79+
80+
Install your custom interpreter of a popular [esoteric programming language](https://esolangs.org/wiki/Esoteric_programming_language) into a Python virtual environment:
81+
82+
```shell
83+
$ cd interpreter/
84+
$ python3 -m venv venv/
85+
$ source venv/bin/activate
86+
(venv) $ python -m pip install .
87+
```
88+
89+
Execute sample scripts through the esoteric language interepreter while using the virtual environment:
90+
91+
```shell
92+
(venv) $ cd scripts/
93+
```
94+
### Towers of Hanoi
95+
96+
```shell
97+
(venv) $ ./hanoi.b
98+
99+
Towers of Hanoi in Brainf*ck
100+
Written by Clifford Wolf <http://www.clifford.at/bfcpu/>
101+
102+
103+
104+
105+
106+
107+
xXXXXXx
108+
xXXXXXXXXXXXXXXXXXXXXXXXXXx xXx
109+
xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx xXXXXXXXXXXXXXx
110+
xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx xXXXXXXXXXXXXXXXXXx
111+
----------------------------------- -----------------------------------
112+
113+
114+
115+
116+
117+
118+
119+
xXXXXXXXXXx
120+
xXXXXXXXXXXXXXXXXXXXXXx
121+
-----------------------------------
122+
```
123+
124+
125+
### Sierpiński Triangle
126+
127+
```shell
128+
(venv) $ ./sierpinski.b
129+
*
130+
* *
131+
* *
132+
* * * *
133+
* *
134+
* * * *
135+
* * * *
136+
* * * * * * * *
137+
* *
138+
* * * *
139+
* * * *
140+
* * * * * * * *
141+
* * * *
142+
* * * * * * * *
143+
* * * * * * * *
144+
* * * * * * * * * * * * * * * *
145+
* *
146+
* * * *
147+
* * * *
148+
* * * * * * * *
149+
* * * *
150+
* * * * * * * *
151+
* * * * * * * *
152+
* * * * * * * * * * * * * * * *
153+
* * * *
154+
* * * * * * * *
155+
* * * * * * * *
156+
* * * * * * * * * * * * * * * *
157+
* * * * * * * *
158+
* * * * * * * * * * * * * * * *
159+
* * * * * * * * * * * * * * * *
160+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
161+
```
162+
163+
164+
### Factorial
165+
166+
```shell
167+
(venv) $ ./factorial.b
168+
1
169+
1
170+
2
171+
6
172+
24
173+
120
174+
720
175+
5040
176+
40320
177+
362880
178+
3628800
179+
39916800
180+
479001600
181+
6227020800
182+
87178291200
183+
1307674368000
184+
20922789888000
185+
355687428096000
186+
6402373705728000
187+
121645100408832000
188+
2432902008176640000
189+
51090942171709440000
190+
1124000727777607680000
191+
25852016738884976640000
192+
620448401733239439360000
193+
15511210043330985984000000
194+
403291461126605635584000000
195+
10888869450418352160768000000
196+
^C
197+
```
198+
199+
### Fibonacci Sequence
200+
201+
```shell
202+
(venv) $ ./fib.b
203+
0
204+
1
205+
1
206+
2
207+
3
208+
5
209+
8
210+
13
211+
21
212+
34
213+
55
214+
89
215+
144
216+
233
217+
377
218+
610
219+
987
220+
1597
221+
2584
222+
4181
223+
6765
224+
10946
225+
17711
226+
28657
227+
46368
228+
75025
229+
121393
230+
196418
231+
^C
232+
```
233+
234+
### ROT-13
235+
236+
```shell
237+
(venv) $ ./rot13.b
238+
This text will be encrypted.
239+
Guvf grkg jvyy or rapelcgrq.
240+
```
241+
242+
### Hello World
243+
244+
```shell
245+
(venv) $ ./hello.b
246+
Hello World!
247+
```

python-shebang/hello.j

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env -S java --source 11
2+
public class Hello {
3+
public static void main(String[] args) {
4+
System.out.println("Hello from Java!");
5+
}
6+
}

python-shebang/hello.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
console.log("Hello from JavaScript!")

python-shebang/hello.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env perl
2+
3+
print "Hello from Perl!\n";

python-shebang/hello.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env python
2+
3+
print("Hello from Python!")

0 commit comments

Comments
 (0)