From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id uPT4J2eEZGNifgEAbAwnHQ (envelope-from ) for ; Fri, 04 Nov 2022 04:17:59 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id IB/9J2eEZGPdGAAAauVa8A (envelope-from ) for ; Fri, 04 Nov 2022 04:17:59 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6F1B138F39 for ; Fri, 4 Nov 2022 04:17:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqnCD-0006cZ-3P; Thu, 03 Nov 2022 23:16:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqnBC-0006aH-Ua for emacs-orgmode@gnu.org; Thu, 03 Nov 2022 23:15:41 -0400 Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqnBB-0003YS-7A for emacs-orgmode@gnu.org; Thu, 03 Nov 2022 23:15:38 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1oqnB7-000AS9-9q for emacs-orgmode@gnu.org; Fri, 04 Nov 2022 04:15:33 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Max Nikulin Subject: Re: processing a literal example line by line in a shell source block? Date: Fri, 4 Nov 2022 10:15:25 +0700 Message-ID: References: <122789.1667413045@archlinux> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Content-Language: en-US In-Reply-To: <122789.1667413045@archlinux> Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 26 X-Spam_score: 2.6 X-Spam_bar: ++ X-Spam_report: (2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Emacs-orgmode" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1667531879; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EXZ6lTZBDBAmj5+xLoEboI2FudsrFux4E2sFT+5lzQw=; b=mql3dLMfYPB1Z25VFkm+F99OpoLf9XFy5u3uDPkTnsO+WdS4jT1bRPOb4sVPWiJoD3bA1Z PO31GE1fRbTcuVrl5fpyAlzn+9uka5uri9LB2QDzHPfpfIKwknlLhfXKEQPIPwoYAhk/lx jUa/XpHh7Drl5MHQY0s58q9aHRQht01sYcG/uWlvK06evOENgGaqzKQSyGS0MRr1FD6F/j z8e8a4vNDb/WjhdoMbRLSry0kfQ/k1034uvsP8A/SFC5a4OmfvlzqjQHwTOnjmo9q9Jc6k UGkwhtBildJi7Am5P8wtGAk9VEE8s3Wl0y6LYmRs419gJ/T4tYCyusfB6hsVow== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1667531879; a=rsa-sha256; cv=none; b=l6ZHn0f87LCyXClkXAVga9u/EWI5UdZypu9Lim8/MZrm5sDy9k1PeHBxHoeclP84F7duMB 0jBlI7wk+aJa8oKsKJjQpdFqLdNowi2froiMz5j4CPB4L+h9455ad5V76q5L2fuB1u+nvv RKjKMTuWRCNdMUAMCXqjcLZIa9OW73iY4lmbNnwQyEFedgUPrRKiD0ecsjFuLMqCZcjRaB oP8iI1Z3YGfEMiF9+XHpqksh2/lT60CDuoTKLH48fpkqOouyVSlU1rrBzCb7XnIweXLvRw GrZ9sYLep+ADUOjHdVAxJrA38IlT6p6S9/D4QmZaMmrumoXfWlz+wtY5kULBKg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 3.70 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 6F1B138F39 X-Spam-Score: 3.70 X-Migadu-Scanner: scn0.migadu.com X-TUID: FBC1dDzlvCaD On 03/11/2022 01:17, Greg Minshall wrote: > hi. i have a text in a named #+begin_example ... #+end_example block. > i would like to process this text line by line in a shell (bash, say) > code block. but, it appears that the individual lines are not > separated, but passed as one long string to the source block. (example > below.) > > #+name: lbl > #+begin_example > line 1 > line 2 > #+end_example You may use :stdin instead of :var, see https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-shell.html #+begin_src bash :stdin lbl while read -r -a arr ; do printf 'value\t%s\n' "${arr[1]}" done #+end_src #+RESULTS: | value | 1 | | value | 2 | > #+begin_src bash :var input=lbl :var in2='("first" "second") > echo ${#input[@]} > echo ${#in2[@]} > echo ${input} > #+end_src There is a nice tool: shellcheck. It should not be difficult to define a function that feeds current source block to it. The only point is to specify shell type since shebang is missed. In some cases even bash -n before running a script may save some time during debugging.