I have some folders with \n character it their names.
for example:
$ ls
''$'\n''Test'
Thats refer to a folder with Test name and a empty line before its name.
So when I run some scripts like this, in its parent directory:
while IFS= read -r d; do
rmdir $d
done < <(find * -type d)
It shows:
rmdir: failed to remove '': No such file or directory
rmdir: failed to remove 'Test': No such file or directory
Because it runs twice, once on \n and the another on Test, because the folder name has two lines.
So how can I solve this issue such that, script knows \nTest is just one folder?
-print0directive, and the-dread option. See https://stackoverflow.com/a/40189667/7552 – glenn jackman Jun 04 '18 at 22:27find * -type d -print0 | while IFS= read -d '' file ; do rmdir $file ; donecommand have this outputrmdir: failed to remove 'Test': No such file or directory. – Tara S Volpe Jun 04 '18 at 22:34rmdir "$file"– glenn jackman Jun 04 '18 at 22:40\before the\ndidn't solve the problem? – damadam Jun 05 '18 at 09:14mkdir $'\nTest'; find . -mindepth 1 -type d -print0 | while IFS= read -r -d '' file; do rmdir -- "$file"; donemost certainly does in fact delete the directory. Can you create a reproducer someone else can run to see a situation where that doesn't take place? The only thing I changed was to add the-mindepth 1so we don't try to delete the directory., and tofind .rather thanfind *so we gracefully deal with names that start with dashes. – Charles Duffy Jun 05 '18 at 18:19