Commit 2b5c09da authored by neilpang's avatar neilpang
Browse files

change shebang if env is not in the default location. fix...

change shebang if env is not in the default location.  fix https://github.com/Neilpang/acmetest/issues/3
parent 97741398
...@@ -495,6 +495,19 @@ _exists() { ...@@ -495,6 +495,19 @@ _exists() {
return $ret return $ret
} }
_findcommand() {
_fcmd="$1"
if command >/dev/null 2>&1; then
command -v "$_fcmd"
elif _exists which; then
which "$_fcmd"
elif eval type type >/dev/null 2>&1; then
eval type $_fcmd | cut -d " " -f 3
else
return 1
fi
}
#a + b #a + b
_math() { _math() {
_m_opts="$@" _m_opts="$@"
...@@ -5966,15 +5979,27 @@ install() { ...@@ -5966,15 +5979,27 @@ install() {
fi fi
if [ -z "$NO_DETECT_SH" ]; then if [ -z "$NO_DETECT_SH" ]; then
_bash_path=""
#Modify shebang #Modify shebang
if _exists bash; then if _exists bash; then
_bash_path="$(bash -c "command -v bash 2>/dev/null")" _bash_path="$(bash -c "command -v bash 2>/dev/null")"
if [ -z "$_bash_path" ]; then if [ -z "$_bash_path" ]; then
_bash_path="$(bash -c 'echo $SHELL')" _bash_path="$(bash -c 'echo $SHELL')"
fi fi
if [ "$_bash_path" ]; then
_info "Good, bash is found, so change the shebang to use bash as preferred."
fi
else
_env="$(_findcommand env)"
_envret="$?"
_debug "_env" "$_env"
if [ "$_envret" = "0" ] && [ "$_env" ] && [ "$_env" != "/usr/bin/env" ]; then
_info "It seems env $_env is not in the default location."
_info "Let's change env shebang."
_bash_path="$_env sh"
fi
fi fi
if [ "$_bash_path" ]; then if [ "$_bash_path" ]; then
_info "Good, bash is found, so change the shebang to use bash as preferred."
_shebang='#!'"$_bash_path" _shebang='#!'"$_bash_path"
_setShebang "$LE_WORKING_DIR/$PROJECT_ENTRY" "$_shebang" _setShebang "$LE_WORKING_DIR/$PROJECT_ENTRY" "$_shebang"
for subf in $_SUB_FOLDERS; do for subf in $_SUB_FOLDERS; do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment