From c814da5f87300abbd7cf0f4caee09a450943de10 Mon Sep 17 00:00:00 2001 From: go2null <1t1is2@gmail.com> Date: Mon, 15 Oct 2018 18:59:00 -0400 Subject: [PATCH] convert to POSIX --- bin/bs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/bin/bs b/bin/bs index ab68001..9c9d1fc 100755 --- a/bin/bs +++ b/bin/bs @@ -1,14 +1,23 @@ -#!/bin/bash +#!/bin/sh -if [[ -f .env ]]; then - eval "$(awk '/^[A-Z]/ { print "export " $0 }' .env)" +bs_function() { + if [ -f '.env' ]; then + # export `.env`. + # NOTE: per design not safe, as env vars are set based on output of + # arbitrary commands defined in `.env`. + eval "$(sed -n 's|^[ \t]*[A-Za-z_][A-Za-z0-9_]*=|export &|p' '.env')" - - if [[ $# -gt 0 ]]; then - "$@" - elif [[ -z $PS2 ]]; then - $SHELL + if [ $# -gt 0 ]; then + # execute command + "$@" + elif [ -z "$PS2" ]; then + # drop to a subshell when not in a command nor being sourced + $SHELL + fi + else + echo 'No .env file found. Aborting.' >&2 + return 1 fi -else - echo "No .env file found. Aborting." >&2 -fi +} + +bs_function "$@"