Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-08 08:36:30

0001 #!/usr/bin/env bash
0002 set -euo pipefail
0003 
0004 # LXPLUS exports a `which` shell function that calls the host's GNU which
0005 # with long options.  When inherited by the EIC container, that function can
0006 # shadow the container's simpler /usr/bin/which and produce "Illegal option"
0007 # errors.  Drop only the inherited function; the container's which remains
0008 # available normally.
0009 unset -f which 2>/dev/null || true
0010 
0011 if [[ "$#" -lt 2 ]]; then
0012     echo "Usage: $0 EIC_SHELL COMMAND [ARGUMENT ...]" >&2
0013     exit 2
0014 fi
0015 
0016 EIC_SHELL=$1
0017 shift
0018 
0019 if [[ ! -x "$EIC_SHELL" ]]; then
0020     echo "eic-shell not found or not executable: $EIC_SHELL" >&2
0021     exit 2
0022 fi
0023 
0024 # The container-side eic-shell accepts a command reliably through stdin.
0025 # Quote every argv element as a single-quoted shell word.  Use the
0026 # '"'"' spelling for an embedded apostrophe so the generated command line
0027 # is safe for the inner shell. Double literal backslashes for eic-shell's
0028 # outer `read` loop (without -r), which consumes one transport-escape layer.
0029 quote_word() {
0030     local value=$1
0031     value=${value//\\/\\\\}
0032     local apostrophe="'\"'\"'"
0033     value=${value//\'/$apostrophe}
0034     printf "'%s'" "$value"
0035 }
0036 
0037 emit_command() {
0038     local first=1
0039     local value
0040     for value in "$@"; do
0041         if (( first )); then
0042             first=0
0043         else
0044             printf ' '
0045         fi
0046         quote_word "$value"
0047     done
0048     printf '\n'
0049 }
0050 
0051 emit_command "$@" | "$EIC_SHELL"