user260223
user260223

Reputation: 125

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 

Upvotes: 0

Views: 1066

Answers (1)

anubhava
anubhava

Reputation: 785196

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.

Upvotes: 2

Related Questions