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# A quoted shell command can contain a single quote by escaping it as \'. This 19# is what lets a single-quoted command itself contain single quotes (an awk 20# program being a very common example), and the double-quoted form honours the 21# same escape. 22# 23 24export SHELL=/bin/sh 25 26function check { 27 typeset desc="$1" expect="$2" got="$3" 28 29 if [[ "$got" != "$expect" ]]; then 30 print -u2 "FAIL [$desc]: expected [$expect], got [$got]" 31 exit 1 32 fi 33} 34 35# 36# \' within a single-quoted command. 37# 38out=$($MDB <<'EOF' 39! 'echo \'hi there\'' 40EOF 41) 42check "squote" "hi there" "$out" 43 44# 45# \' within a double-quoted command. 46# 47out=$($MDB <<'EOF' 48! "echo \'hi there\'" 49EOF 50) 51check "dquote" "hi there" "$out" 52 53# 54# An awk program delimited and quoted with \'. 55# 56out=$($MDB <<'EOF' 57! 'awk \'BEGIN { print "ok" }\'' 58EOF 59) 60check "awk" "ok" "$out" 61 62exit 0 63