filename with space

后端 未结 3 871
梦如初夏
梦如初夏 2021-01-21 23:34

I have written a shell script which picks all the files recursively inside all the directories and prepared a report with the file last modified, size. The problem that I am fac

相关标签:
3条回答
  • 2021-01-22 00:02

    You're probably trying to use something like for file in $(command). Instead, use a while read loop or a for loop with globbing. Make sure you quote variables that contain filenamess.

    #!/bin/sh
    command | while read -r file
    do
        something_with "$file"
    done
    

    or, in shells that support process substitution:

    #!/bin/bash
    while read -r file
    do
        something_with "$file"
    done < <(command)
    

    If you're simply iterating over a list of files:

    for file in "$dir"/*
    do
        something_with "$file"
    done
    
    0 讨论(0)
  • 2021-01-22 00:12

    Just put the file name variable between double quotes "$FILENAME"

    0 讨论(0)
  • 2021-01-22 00:12

    Google Search led me to this page

    0 讨论(0)
提交回复
热议问题