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.
精彩评论