Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check valid python more strictly in shell entry point #258

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions guider/guider
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you restrict the shell to bash?
It will cause error on systems without bash.
There are also various shells such as dochsh, dash, rbash, rsh...


# Guider Launcher
#
# Copyright (c) 2016-2021 Peace Lee <[email protected]>
Expand All @@ -7,22 +9,14 @@
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.

# check python #
if [ ! $PYTHON ]
# check valid Python in order: user-specified, python, python3 and 2 #
if [ z`$PYTHON -V 2>/dev/null | cut -d' ' -f1` != "zPython" ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using regular expressions instead of external commands like cut?

then
PYTHON=$(which python)
if [ ! $PYTHON ]
PYTHON=`which python || which python3 || which python2`
if [ z`$PYTHON -V 2>/dev/null | cut -d' ' -f1` != "zPython" ]
then
PYTHON=$(which python3)
if [ ! $PYTHON ]
then
PYTHON=$(which python2)
if [ ! $PYTHON ]
then
echo "[Error] fail to find python"
exit
fi
fi
echo "[Error] fail to find python"
exit
fi
fi

Expand Down