FG
💻 Software

Making BASH script `for` handle filenames with spaces (or workaround)

Fresh5 days ago
Mar 15, 202617126 views
Confidence Score0%
0%

Problem

Whilst I have been using BASH for several years, my experience with BASH scripting is relatively limited. My code is as below. It should grab the entire directory structure from within the current directory and replicate it into . The problem is, here is a sample of my file structure: Note the spac…

Error Output

for DIR in `find . -type d -printf "\"%P\"\040"`
do
  echo mkdir -p \"${OUTPATH}${DIR}\"        # Using echo for debug; working script will simply ex…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Making BASH script `for` handle filenames with spaces (or workaround)

Low Risk

You need to pipe the into a loop. Also, you won't need to use in this case. You can make this proof against files with newlines in their names, if you wish, by using a nullbyte delimiter (that being the only character which cannot appear in a *nix f…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment