filename contains space and wildcard in a variable

前端 未结 3 1002
难免孤独
难免孤独 2021-01-07 11:35

I receive files which names contain spaces and change every week (the name contains the week number)

IE, the file for this week looks like This is the file - w

3条回答
  •  北海茫月
    2021-01-07 11:47

    Use a bash array

    v=( /dir/This\ is\ the\ file - w*.csv )
    

    If there is guaranteed to be only one matching file, you can just expand $v. Otherwise, you can get the full list of matching files by expanding as

    "${v[@]}"
    

    or individual matches using

    "${v[0]", "${v[1]}", etc
    

提交回复
热议问题