xref: /illumos-gate/usr/src/test/util-tests/tests/mdb/shell/tst.source.ksh (revision 3d4e20a23e1894c03df6b83e39a88625f74ee0e4)
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 "!<" shell input escape, which runs a shell command and then
19# evaluates its standard output as debugger commands. Both the bare form and
20# the pipeline form (where dcmd output is first sent to the command) are
21# covered. ::echo appends a trailing space after the last word, which is
22# trimmed before comparing.
23#
24
25export SHELL=/bin/sh
26
27function check {
28	typeset desc="$1" expect="$2" got="$3"
29
30	if [[ "$got" != "$expect" ]]; then
31		print -u2 "FAIL [$desc]: expected [$expect], got [$got]"
32		exit 1
33	fi
34}
35
36#
37# Bare form: the command emits a debugger command, which is then sourced and
38# run.
39#
40out=$($MDB <<'EOF'
41!< echo '::echo sourced'
42EOF
43)
44out=${out% }
45check "source" "sourced" "$out"
46
47#
48# Pipeline form: the output of the dcmd is fed to the shell command, whose
49# output is collected and then sourced once the pipeline has completed.
50#
51out=$($MDB <<'EOF'
52::echo 10 20 30 !< awk '{print "::echo total " $1+$2+$3}'
53EOF
54)
55out=${out% }
56check "source-pipe" "total 60" "$out"
57
58exit 0
59