1#!/usr/bin/ksh 2# 3# This file and its contents are supplied under the terms of the 4# Common Development and Distribution License ("CDDL"), version 1.0. 5# You may only use this file in accordance with the terms of version 6# 1.0 of the CDDL. 7# 8# A full copy of the text of the CDDL should have accompanied this 9# source. A copy of the CDDL is also available via the Internet at 10# http://www.illumos.org/license/CDDL. 11# 12 13# 14# Copyright 2026 Oxide Computer Company 15# 16 17# 18# Exercise the simple shell escape "! command", which spawns $SHELL -c and 19# sends the command's output to the terminal. This drives the posix_spawn 20# path in mdb_shell_exec(). 21# 22 23export SHELL=/bin/sh 24 25function check { 26 typeset desc="$1" expect="$2" got="$3" 27 28 if [[ "$got" != "$expect" ]]; then 29 print -u2 "FAIL [$desc]: expected [$expect], got [$got]" 30 exit 1 31 fi 32} 33 34# 35# A plain, unquoted command. Everything up to the newline is handed to the 36# shell. 37# 38out=$($MDB <<'EOF' 39! echo spawned 40EOF 41) 42check "plain" "spawned" "$out" 43 44# 45# A single-quoted command, which may itself contain a semicolon without it 46# being taken as a debugger command separator. 47# 48out=$($MDB <<'EOF' 49! 'echo one; echo two' 50EOF 51) 52check "squote-semi" $'one\ntwo' "$out" 53 54# 55# A double-quoted command, whose body is subject to C escape processing. 56# 57out=$($MDB <<'EOF' 58! "echo hello" 59EOF 60) 61check "dquote" "hello" "$out" 62 63# 64# A double-quoted command may contain single quotes verbatim, as needed for an 65# awk program. 66# 67out=$($MDB <<'EOF' 68! "awk 'BEGIN { print 42 }'" 69EOF 70) 71check "dquote-squote" "42" "$out" 72 73exit 0 74