Ant*_*res 1 linux bash shell tar
这是一个非常简短的问题.但是$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
Run Code Online (Sandbox Code Playgroud)
注意"echo tar ......".当我复制并粘贴输出并在我的终端中运行它时,tar文件没有问题.我目前正在运行Xubuntu,我已经做了更新.
~ 不会用双引号扩展到您的主目录.
只需删除双引号:
backup_source=~/momobobo
backup_dest=~/momobobo_backup/
Run Code Online (Sandbox Code Playgroud)
如果您有想要引用的东西,可以使用 ~/"momobobo"