1
#!/bin/bash

current_date=$(date +"%m-%d-%Y")
file="name Backup ($current_date)"
tar -cvzf $file.tgz module8

My output needs to be named "name Backup $current_date"

When I run the script is just names the file "name" not even "name.tgz"

This is what I get for an output

name | 175 kB | 175.0 kB/s | ETA: 00:00:00 | 100%

Backup: No such file or directory

(03-16-2019).tgz: No such file or directory

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

2 Answers2

2

The tar command receives the variable contents as whitespace separated list of arguments. You do not want that, you need to quote them:

tar -cvzf "$file.tgz" module8
Hermann
  • 6,148
1

Okay I figured out what I was doing wrong... Line 4 needed to be file="name Backup ($current_date).tgz" Line 5 needed to be tar -cvzf "$file" module8