-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpython_web_serve.sh
executable file
·52 lines (44 loc) · 1.02 KB
/
python_web_serve.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Defaults - Listen on localhost:9000 only:
PORT=9000
BIND="--bind 127.0.0.1"
#python -m SimpleHTTPServer $PORT
#python2 -m SimpleHTTPServer $PORT
#python3 -m SimpleHTTPServer $PORT
#PYTHON=python
PYTHON=python3
while [ ! -z "$1" ]; do
case $1 in
[0-9]*.*:[0-9]*)
echo "ARG ip:port <$1>"
ARG=$1; PORT=${ARG#*:} BIND=${ARG%:*}
BIND="--bind $BIND"
;;
#echo TEST-num-col;;
[0-9]*.*)
echo "ARG ip <$1>"
BIND=$1
BIND="--bind $BIND"
;;
[0-9]*)
echo "ARG port <$1>"
ARG=$1; PORT=$1
;;
*) echo "NOMATCH on <$1>";;
esac
shift
done
echo BIND=$BIND PORT=$PORT
#$PYTHON --version |& grep -i "python 2\." && {
$PYTHON --version 2>&1 | grep -i "python 2\." && {
# Python2:
echo Python2
python2 -m SimpleHTTPServer $PORT
exit $?
} || {
# Python3:
echo Python3
PYTHON=python3
$PYTHON -m http.server $PORT $BIND
exit $?
}