/** @see execShellLine — nounset violations surface as exit status 1 */ export const BARE_OS_SHELL_NOUNSET_ERROR = 'BARE_OS_SHELL_NOUNSET' /** * @param {Record | null | undefined} env */ export function shellNounsetEnvOn(env) { return ( env && (env.BARE_OS_SHELL_NOUNSET === '1' || env.BARE_OS_SHELL_NOUNSET === 'true') ) } /** * @param {string} name * @param {Record} env */ export function shellCheckUnboundParam(name, env) { if (!shellNounsetEnvOn(env) || !name) return const n = name.trim() if (n === '?' || /^\d+$/.test(n)) return if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(n)) return if (!Object.prototype.hasOwnProperty.call(env, n)) { const e = new Error(`unbound variable: ${n}`) e.code = BARE_OS_SHELL_NOUNSET_ERROR throw e } }