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 "dcmd ! command" form, which sends the output of the preceding 19# dcmd to $SHELL -c and the command's output to the terminal. This drives the 20# posix_spawn path in mdb_shell_pipe(). 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 filter. ::echo appends a trailing space after the last 36# word, which the pass-through filter preserves, so trim it before comparing. 37# 38out=$($MDB <<'EOF' 39::echo abc ! tr a-z A-Z 40EOF 41) 42out=${out% } 43check "plain" "ABC" "$out" 44 45# 46# A single-quoted awk filter, quoted with \', as a user is most likely to 47# write it. 48# 49out=$($MDB <<'EOF' 50::echo alpha beta gamma ! 'awk \'{print $3}\'' 51EOF 52) 53check "squote-awk" "gamma" "$out" 54 55# 56# The same with the double-quoted form, where the single quotes around the awk 57# program need no escaping. 58# 59out=$($MDB <<'EOF' 60::echo alpha beta gamma ! "awk '{print $2}'" 61EOF 62) 63check "dquote-awk" "beta" "$out" 64 65# 66# A double-quoted awk program with the inner double quotes escaped as \" and 67# the field reference protected from the shell with \$, so that the $1 reaches 68# awk rather than being expanded by the shell. 69# 70out=$($MDB <<'EOF' 71::echo alpha beta gamma ! "awk \"{print \$1}\"" 72EOF 73) 74check "dquote-escdollar" "alpha" "$out" 75 76exit 0 77