如何解决给变量加上双引号
我有以下脚本,我需要将变量$ 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
它在我需要的文件周围添加了双引号。
我想我错过了{}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。