给变量加上双引号

问题描述

我有以下脚本,我需要将变量$ f用双引号括起来,因为某些文件中有空格:

# create a reftime (for the last 24 hours)
((reftime=$(date '+%s')-(24*60*60)))
# create a reffile for that time in /var/tmp (or any other place)
reffile=/var/tmp/reffile.$$.tmp
touch --date=@${reftime} ${reffile}

# find all files (in srcbase),that was changed in the last 24h - that means
# Now all files that are newer then our reffile,and copy to destbase...
srcbase=/myorigin
dest=gpadmin@10.0.1.8:/mydest/dest

# for all of these files we need the directory names (because we need the structure for copy)
chgfiles=/var/tmp/chgfile.$$.tmp
find ${srcbase} -type f -newer $reffile 2>/dev/null | sort -u >${chgfiles}

cat ${chgfiles} | while read f ; do
 # echo "copy file $f to destination $dest ..."
  # create directory structures if not exist
  #mkdir -p "${dest}"
  # and finaly cp the file
scp "$f" $dest
done

# clear all tmp files
rm ${reffile} ${chgfiles}

我尝试了scp "$f" $dest,但是没有用。.

有什么想法吗?

谢谢!

解决方法

这有效:

scp "${f}" $dest

它在我需要的文件周围添加了双引号。

我想我错过了{}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...