这是一个非常简短的问题。但是放置变量是否存在语法错误$example
作为 bash 文件中 tar 的参数?
我将文件写为
//only portion that really matters
#!/bin/bash
...
tar -cvpzf $filename $backup_source
//here's the actual code
#!/bin/bash
backup_source="~/momobobo"
backup_dest="~/momobobo_backup/"
dater=`date '+%m-%d-%Y-%H-%M-%S'`
filename="$backup_dest$dater.tgz"
echo “Backing Up your Linux System”
tar -cvpzf $filename $backup_source
echo tar -cvpzf $filename $backup_source
echo “Backup finished”
//and heres the error
“Backing Up your Linux System”
tar: ~/momobobo: Cannot stat: No such file or directory
tar (child): ~/momobobo_backup/07-02-2013-18-34-12.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
tar -cvpzf ~/momobobo_backup/07-02-2013-18-34-12.tgz ~/momobobo
注意“echo tar ...”。当我复制并粘贴输出并在终端中运行它时,没有问题tar
荷兰国际集团的文件。我目前正在运行 Xubuntu 并且我已经进行了更新。
~
不会扩展到双引号中的主目录。
只需删除双引号:
backup_source=~/momobobo
backup_dest=~/momobobo_backup/
如果您有想要引用的内容,您可以使用~/"momobobo"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)