I am currently writing some scripts to be utilized in an alpine linux container, and I want this be as lightweight as possible so I am refraining from installing bash
. I plan on sourcing a shell script, but don't want it to execute when I source
it.
I understand that if I was using bash
I could easily do the following:
#!/usr/bin/env bash
set -e
main(){
echo "something witty"
}
if [[ "$_" -eq "$0" ]]; then
main
fi
But I am drawing a blank for sh
.
Here is a demo of the lack of ability to us $_
in sh
for an attempt at simular functionality:
/ # ./test.sh
+ echo
/ # cat test.sh
#!/bin/sh
set -ex
echo "$_"
/ # echo "$_"
test.sh
/ #
Any recommendations?