Shell-Script

在變數中連接文件名

  • June 18, 2015

我正在嘗試連接文件名以在 ftp mdelete 命令中使用。為了使 mdelete 命令起作用,每個文件名都需要用空格分隔。這 $ i variable is in a loop and I am attempting to assign the file name located into $ 我要 $ FILESTODELETE in addtion to the file names already in $ 文件刪除

 for i in `ls`
   do    
   $FILESTODELETE = "$FILESTODELETE $i "
       .....
    END
......     

mdelete $FILESTODELETE
set -- *
filenames="$*"

只要您沒有修改環境的值 $ IFS, the above is all you need to get all of the names of not-dot files in the current directory into a single string as divided by spaces and sorted by locale in any POSIX shell. If you have modified $ IFS,那麼無論它的第一個字元是什麼,都將替代剛才提到的單個空格分隔符。

但請注意,上述內容並不能保證所述文件名不包含空格、換行符或基本上除 NUL 或 / 之外的任何字元——這些可能不在文件名中。

引用自:https://unix.stackexchange.com/questions/210653