{"id":3766,"date":"2018-02-08T20:34:32","date_gmt":"2018-02-08T19:34:32","guid":{"rendered":"https:\/\/monodes.com\/predaelli\/?p=3766"},"modified":"2018-02-08T08:34:55","modified_gmt":"2018-02-08T07:34:55","slug":"how-can-i-escape-white-space-in-a-bash-loop-list-stack-overflow","status":"publish","type":"post","link":"https:\/\/monodes.com\/predaelli\/2018\/02\/08\/how-can-i-escape-white-space-in-a-bash-loop-list-stack-overflow\/","title":{"rendered":"How can I escape white space in a bash loop list? &#8211; Stack Overflow"},"content":{"rendered":"<div class=\"post-text\">\nI find this nice and elegant. The other proposed solutions may handle files with newline in their name, but currently I see such file names as nonsense\n<\/div>\n<blockquote>\n<div class=\"post-text\">\n<pre class=\"lang-sh prettyprint prettyprinted\"><code class=\"\" data-line=\"\">&lt;span class=&quot;pln&quot;&gt;find &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;\/span&gt; &lt;span class=&quot;pun&quot;&gt;-&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt;type d &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;kwd&quot;&gt;while&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt; read file&lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;;&lt;\/span&gt; &lt;span class=&quot;kwd&quot;&gt;do&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt; echo $file&lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;;&lt;\/span&gt; &lt;span class=&quot;kwd&quot;&gt;done&lt;\/span&gt;<\/code><\/pre>\n<p>However, doesn&#8217;t work if the file-name contains newlines. The above is the only solution i know of when you actually want to have the directory name in a variable. If you just want to execute some command, use xargs.<\/p>\n<pre class=\"lang-sh prettyprint prettyprinted\"><code class=\"\" data-line=\"\">&lt;span class=&quot;pln&quot;&gt;find &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;\/span&gt; &lt;span class=&quot;pun&quot;&gt;-&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt;type d &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt;print0 &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;|&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt; xargs &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;-&lt;\/span&gt;&lt;span class=&quot;lit&quot;&gt;0&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt; echo &lt;\/span&gt;&lt;span class=&quot;str&quot;&gt;&#039;The directory is: &#039;&lt;\/span&gt;<\/code><\/pre>\n<\/div>\n<\/blockquote>\n<p>Sorgente: <em><a href=\"https:\/\/stackoverflow.com\/questions\/301039\/how-can-i-escape-white-space-in-a-bash-loop-list#301059\">How can I escape white space in a bash loop list? &#8211; Stack Overflow<\/a><\/em><\/p>\n<p>Furthermore <a href=\"https:\/\/www.cyberciti.biz\/tips\/handling-filenames-with-spaces-in-bash.html\">BASH Shell: For Loop File Names With Spaces<\/a> suggets:<\/p>\n<blockquote>\n<pre class=\"bash\">find . -print0 | while read -d $'\\0' file\ndo\n  echo -v \"$file\"\ndone<br \/><br \/><\/pre>\n<\/blockquote>\n<p>that should handle even the weirdest file name<\/p>\n<p><!--more--><\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">I find this nice and elegant. The other proposed solutions may handle files with newline in their name, but currently I see such file names as nonsense &lt;span class=&quot;pln&quot;&gt;find &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;\/span&gt; &lt;span class=&quot;pun&quot;&gt;-&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt;type d &lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;|&lt;\/span&gt; &lt;span class=&quot;kwd&quot;&gt;while&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt; read file&lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;;&lt;\/span&gt; &lt;span class=&quot;kwd&quot;&gt;do&lt;\/span&gt;&lt;span class=&quot;pln&quot;&gt; echo $file&lt;\/span&gt;&lt;span class=&quot;pun&quot;&gt;;&lt;\/span&gt; &lt;span class=&quot;kwd&quot;&gt;done&lt;\/span&gt; However, doesn&#8217;t work if&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/monodes.com\/predaelli\/2018\/02\/08\/how-can-i-escape-white-space-in-a-bash-loop-list-stack-overflow\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"link","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[72],"tags":[],"class_list":["post-3766","post","type-post","status-publish","format-link","hentry","category-documentations","post_format-post-format-link"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6daft-YK","jetpack-related-posts":[{"id":9377,"url":"https:\/\/monodes.com\/predaelli\/2022\/05\/13\/increase-open-files-limit-solution-for-too-many-open-files-24\/","url_meta":{"origin":3766,"position":0},"title":"Increase &#8220;Open Files Limit&#8221;. Solution for &#8220;Too many open files (24)&#8221;","author":"Paolo Redaelli","date":"2022-05-13","format":false,"excerpt":"Increase \"Open Files Limit\". Solution for \"Too many open files (24)\" If you are getting error \u201cToo many open files (24)\u201d then your application\/command\/script is hitting max open file limit allowed by linux. You need to increase open file limit as below: Increase limit Per-User Limit Open file:\u00a0\/etc\/security\/limits.conf Paste following\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9532,"url":"https:\/\/monodes.com\/predaelli\/2022\/08\/09\/7-python-one-liners-that-will-blow-your-mind\/","url_meta":{"origin":3766,"position":1},"title":"7 Python One-Liners that will Blow Your Mind","author":"Paolo Redaelli","date":"2022-08-09","format":false,"excerpt":"Xiaoxu Gao wrote 7 Python One-Liners that will Blow Your Mind Less is more? Photo by Photos by Lanty from Unsplash The term one-liner comes from comedy where a joke is delivered in a single line. A good one-liner is said to be meaningful and concise. This concept also exists\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/monodes.com\/predaelli\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":14800,"url":"https:\/\/monodes.com\/predaelli\/2026\/01\/24\/ventoy-a-new-bootable-usb-solution\/","url_meta":{"origin":3766,"position":2},"title":"Ventoy A New Bootable USB Solution","author":"Paolo Redaelli","date":"2026-01-24","format":false,"excerpt":"Ventoy A New Bootable USB Solution Ventoy is an open source tool to create bootable USB drive for ISO\/WIM\/IMG\/VHD(x)\/EFI files.With Ventoy, you don't need to format the disk over and over, you just need to copy the ISO\/WIM\/IMG\/VHD(x)\/EFI files to the USB drive and boot them directly.You can copy many\u2026","rel":"","context":"In &quot;Software&quot;","block_context":{"text":"Software","link":"https:\/\/monodes.com\/predaelli\/category\/software\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/monodes.com\/predaelli\/wp-content\/uploads\/sites\/4\/2026\/01\/ventoy.webp?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":7144,"url":"https:\/\/monodes.com\/predaelli\/2020\/04\/30\/little-notes\/","url_meta":{"origin":3766,"position":3},"title":"Little notes","author":"Paolo Redaelli","date":"2020-04-30","format":false,"excerpt":"Just a little note to myself, to start salome on a severly hacked and messed up workstation like mine: paolo@rigel:~\/salome_meca\/appli_V2019.0.3_universal$ \/home\/paolo\/salome_meca\/appli_V2019.0.3_universal\/salome runSalome running on rigel Searching for a free port for naming service: 2815 - OK Searching Naming Service + found in 0.1 seconds Searching \/Kernel\/Session in Naming Service ++++libGL\u2026","rel":"","context":"In &quot;Documentations&quot;","block_context":{"text":"Documentations","link":"https:\/\/monodes.com\/predaelli\/category\/documentations\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8386,"url":"https:\/\/monodes.com\/predaelli\/2021\/04\/25\/your-source-code-is-public-if-you-dont-know-this-simple-trick-by-shoaib-mehedi-dev-genius-apr-2021-medium\/","url_meta":{"origin":3766,"position":4},"title":"Your source code is public if you don\u2019t know this simple trick. | by Shoaib Mehedi | Dev Genius | Apr, 2021 | Medium","author":"Paolo Redaelli","date":"2021-04-25","format":false,"excerpt":"Please read \u00abYour source code is public if you don\u2019t know this simple trick.\u00bb\u00a0 by Shoaib Mehedi. Read it carefully. Then please someone may feel the urge to explain the concept of \"Software Libero\" to Shoaib Mehedi. Please tell him that obfuscating javascript is not a solution for his needs,\u2026","rel":"","context":"In &quot;Ethics&quot;","block_context":{"text":"Ethics","link":"https:\/\/monodes.com\/predaelli\/category\/ethics\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":13841,"url":"https:\/\/monodes.com\/predaelli\/2025\/08\/12\/some-sources-can-be-modernized-run-apt-modernize-sources-to-do-so\/","url_meta":{"origin":3766,"position":5},"title":"Some sources can be modernized. Run \u2018apt modernize-sources\u2019 to do so","author":"Paolo Redaelli","date":"2025-08-12","format":false,"excerpt":"Thanks to Alan Pope that explained so clearly the Run \u2018apt modernize-sources\u2019 to do so issue at discourse.ubuntu.com: The notice \u201cSome sources can be modernized. Run \u2018apt modernize-sources\u2019 to do so\u201d appears because your Ubuntu system has detected software repository configurations using the older, traditional format (.list files, typically \/etc\/apt\/sources.list\u2026","rel":"","context":"In &quot;Debian&quot;","block_context":{"text":"Debian","link":"https:\/\/monodes.com\/predaelli\/category\/debian\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/3766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/comments?post=3766"}],"version-history":[{"count":0,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/posts\/3766\/revisions"}],"wp:attachment":[{"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/media?parent=3766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/categories?post=3766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/monodes.com\/predaelli\/wp-json\/wp\/v2\/tags?post=3766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}