开发者

Compress a dictionary with shell script

I want to compress a dictionary with this format: 2011.16.03_root_backup.tar.gz (date followed by username). But my shell script code doesn't working and some missing code. May you help me please?

#!/bin/sh
date=$(date +"开发者_如何学编程%y-%d-%m")
user=$(whoami)
target=(i want to get this as an argument)
tar -cvf ./$date_$user_backup.tar.gz $target 


Try this line for your tar command:

tar -czvf ./${date}_${user}_backup.tar.gz ${target}

Problem was that _ after $date or $user is not considered a word separator by shell that's why ${var} form is needed here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜