小编Ant*_*res的帖子

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: …
Run Code Online (Sandbox Code Playgroud)

linux bash shell tar

1
推荐指数
1
解决办法
4002
查看次数

标签 统计

bash ×1

linux ×1

shell ×1

tar ×1