From owner-freebsd-questions@freebsd.org Fri Oct 16 13:01:57 2020 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3A1F1434EA2 for ; Fri, 16 Oct 2020 13:01:57 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailman.nyi.freebsd.org (mailman.nyi.freebsd.org [IPv6:2610:1c1:1:606c::50:13]) by mx1.freebsd.org (Postfix) with ESMTP id 4CCRBF0Dywz4vPV for ; Fri, 16 Oct 2020 13:01:57 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: by mailman.nyi.freebsd.org (Postfix) id 07FC5434DCE; Fri, 16 Oct 2020 13:01:57 +0000 (UTC) Delivered-To: questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 07C61434EA1 for ; Fri, 16 Oct 2020 13:01:57 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CCRBC6R2tz4vfy for ; Fri, 16 Oct 2020 13:01:55 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([94.222.3.6]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPA (Nemesis) id 1MIdW7-1khS6s2Mj7-00EfMv; Fri, 16 Oct 2020 15:01:43 +0200 Date: Fri, 16 Oct 2020 15:01:43 +0200 From: Polytropon To: Robert Huff Cc: questions@freebsd.org Subject: Re: sh scripting question Message-Id: <20201016150143.9ee6e90f.freebsd@edvax.de> In-Reply-To: <24456.60388.135834.43951@jerusalem.litteratus.org> References: <24456.60388.135834.43951@jerusalem.litteratus.org> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:BwxKUo6ZOl7bXmarjmnoFIKK40wi98L3aYh5A7Z4O8/eDZ35Lp8 Vtlm9SBDrKMtjaNqrMq/P6CLDfBy9g27UbolkpAk11olyvhVd7cJBN1G8Dn1zEOH0NSX6ib 5MSWNDP4vc3NEIssjxuQpQGRcKZIfzFlG5u7BGmvGMRG+bA4KESasTi0Ae/4NZYaVyJYtDQ Kz1iTriMRe31Bht7JnylQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:MLno05pUohI=:nLDpkkXIW1+3B8HKSUaEt4 CksgnM3nfzNjfDErWicpYf/lkEsVPoW0NbV7LGyio1LDfN/ZycdfQJ1Ctiv6yqCoOGeG/qyrN KZ7XU2iuC/l1hifP92JKUvJp1Bi/4UjNwj450QeJmU2RfQd/ELGulh48m83/aD3qNVmnpmTGU BlPIDmRVKnSAfNACRfDjP239fbSqzfjrF4Oe7U3co1gH6kuGveTLJq7V7VfOb+OyL6y0QPqcT xD8h6j19Xfj8PmW0vzHe355SlAEOo2mILjbRy7ueMXnydgq94B+2zqO7eaHlcyyOZ5wyJ7DLZ g4AAQelmN+YnsEQ/ce1ynnltPwJ0lMxaIC7GvfCbKIdv54ArkTbPfZXoF3mOmK5E7PinpC++r ppJCUPaAmzO8Em5aVmZdaooDqbtmmRWScGS/zU79yl0f/XO0jwNpwUAF/eld6 X-Rspamd-Queue-Id: 4CCRBC6R2tz4vfy X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of freebsd@edvax.de has no SPF policy when checking 212.227.17.13) smtp.mailfrom=freebsd@edvax.de X-Spamd-Result: default: False [-0.13 / 15.00]; HAS_REPLYTO(0.00)[freebsd@edvax.de]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; HAS_ORG_HEADER(0.00)[]; NEURAL_HAM_SHORT(-1.03)[-1.034]; RCPT_COUNT_TWO(0.00)[2]; RECEIVED_SPAMHAUS_PBL(0.00)[94.222.3.6:received]; RCVD_TLS_LAST(0.00)[]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:8560, ipnet:212.227.0.0/16, country:DE]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.70)[-0.696]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-0.80)[-0.804]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[edvax.de]; AUTH_NA(1.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[212.227.17.13:from]; R_SPF_NA(0.00)[no SPF record]; RWL_MAILSPIKE_POSSIBLE(0.00)[212.227.17.13:from]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[questions] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2020 13:01:57 -0000 On Thu, 15 Oct 2020 20:40:04 -0400, Robert Huff wrote: > > I have a file ("files.list") with a list of filenames, similar to > > /path A/path B/FreeBSD is great.txt > > (note the embedded spaces) > If I use > > for FILE in `cat files.list` > > FILE will be set to "/path". > How do I get it to read the entire string? > Or am I using the wrong tool? Generally speaking, you need to set IFS, the input field separator, to newline instead of space. You also have to pay attention to every point during the script you will use ${FILE}. For example: OLD_IFS=$IFS IFS=" " for FILE in `cat files.list`; do something ... "${FILE}" done IFS=$OLD_IFS Instead of a literal linebreak, you could probably also use something more elegant like IFS=`printf "\n"`. Also note the quotes around each use of ${FILE}. But: Whenever this comes up - spaces in filenames -, I tend to suggest _first_ reading the following two articles: Filenames and Pathnames in Shell: How to do it Correctly David A. Wheeler 2020-02-22 (original version 2010-05-19) https://dwheeler.com/essays/filenames-in-shell.html And: Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems David A. Wheeler 2019-03-18 (originally 2009-03-24) https://dwheeler.com/essays/fixing-unix-linux-filenames.html There is so much wisdom and knowledge in those articles, you won't regret reading them, thinking about them, and finally understanding the problem space you've entered. :-) You can easily use sh for processing such filenames if you take care for a few important things. Especially if you do not have the option to "normalize" the names, i. e., replace spaces with underscores (the common replacement character), there is a way you can go. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...