Path: csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Ilkka Virta Newsgroups: gnu.bash.bug Subject: Re: Feature Request: Custom delimeter for single quotes Date: Fri, 1 Nov 2019 10:37:50 +0200 Lines: 76 Approved: bug-bash@gnu.org Message-ID: References: <13ecc4db-2b5e-95dd-2445-78191b9c01dd@iki.fi> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1572597484 30530 209.51.188.17 (1 Nov 2019 08:38:04 GMT) X-Complaints-To: action@cs.stanford.edu To: Patrick Blesi , bug-bash@gnu.org Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 In-Reply-To: Content-Language: en-US X-SASI-RCODE: 200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; h=subject:to:references:from:message-id:date:mime-version:in-reply-to:content-type:content-transfer-encoding; s=smtp; bh=9x1+RTDgDArsZ5g8zNEYGp/GtjrMrWYl62+b/YJNVaQ=; b=x/rmgByDM/DnxCu+a5k8yNSDyizyDGNPZ6Aw/kN6bYNR5wJYgMakEf7/bnid6cVdmdwiRU30Dgh/aW1paWLN9MTSDErj27C3b68UZ1e10oAlqZ6t0pfubB0NfToZXGEd7XccJg4nf3hqOJTOZabA9u9mxU6L14mCOEOQSjFCKuFeYKoPf4Pm1gth0Xmqw9GyCfeXzXFhp7YTr0NppqQIPm3+Lj6TfQORK6G5r7MtrnB7IsDo19TDNb/2LVKp7MlzTUj/uRYLYrgUl0ewgnpms5Y87/SeX48CYU0FQK5hOfcz4A7OCsNflhMwpySIXaf67k71cVluU0K5dDqq4iEmGA== X-detected-operating-system: by eggs.gnu.org: FreeBSD 8.x [fuzzy] X-Received-From: 157.24.2.213 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <13ecc4db-2b5e-95dd-2445-78191b9c01dd@iki.fi> X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:15551 On 1.11. 06:54, Patrick Blesi wrote: > I'm looking for a hybrid between single quotes and a here doc or here > string. >=20 > The main use case is for accepting arbitrary user-specified text.=20 Do your users enter the text by directly editing the script? Would it make more sense to use e.g. 'read' to read the input directly=20 from the user? input=3D"" nl=3D' ' echo "Enter text, end with ^D:" while IFS=3D read -r line; do input=3D"$input$line$nl" done printf "You entered:\n---\n%s---\n" "$input" or to just have the text in a separate file (not the script) and read it=20 from there? input=3D$(< inputfile) That way, the text appears in a variable, and you don't need to care=20 about quotes inside it. (You could also read from stdin with just input=3D$(cat) instead of the= =20 while read loop but that feels a bit odd to me for some reason.) > I would > like to wrap this text in single quotes so as to prevent any variable > expansion or interpretation of the text of any kind. Additionally, I wo= uld > like to allow the users to include single quotes in their text without > requiring that they escape these quotes. >=20 > Something akin to the following would alleviate the need to communicate > that users must escape single quotes, but also provide the same literal > string behavior of single quotes. >=20 > presuming the arbitrarily substituted text is: >=20 > echo 'this command is specified by the user' >=20 > Then a syntax for this single quote heredoc behavior could be like: >=20 > $ sh -c <<^MAGIC_WORD echo 'this command is specified by the user' > MAGIC_WORD >=20 > Everything within the MAGIC_WORD declarations would not have command > substitution, variable expansion, etc, but would be treated as if it we= re > wrapped in single quotes with the exception that single quotes between = the > MAGIC_WORDs need not be escaped. >=20 > Pardon my na=C3=AFvet=C3=A9, does any such feature exist or are there g= ood ways to > accomplish this? If not, is this something that could feasibly be > implemented? Would it be desirable? >=20 > Thanks, >=20 > Patrick >=20 --=20 Ilkka Virta / itvirta@iki.fi