Linux shell script shebang env All In One

xgqfrms / 2023-05-03 / 原文

Linux shell script shebang env All In One

指定 shell script 的运行环境

shell script shebang env

hash bang env

#!\usr\bin\env bash

#!\usr\bin\env bash
# ❌

#!/usr/bin/env

#!/usr/bin/env bash
✅

demos

image

image

#!/usr/bin/env bash
# ✅

export N=1
# case 1 数字
# suceess exit ✅

# ✅
case "$N" in
  1)
    echo 'case 1 数字';;
  2)
    echo 'case 2 数字';;
  *)
    echo 'default case 数字 *'
    echo 'error exit ❌'
    exit 1
  ;;
esac

echo 'suceess exit ✅'
exit 0

refs

https://www.cyberciti.biz/tips/finding-bash-perl-python-portably-using-env.html

https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my

https://www.baeldung.com/linux/bash-shebang-lines

https://stackoverflow.com/questions/43793040/how-does-usr-bin-env-work-in-a-linux-shebang-line



©xgqfrms 2012-2021

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!