Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:52:52+00:00 2026-06-12T06:52:52+00:00

For class we have to work on a remote server that the school hosts.

  • 0

For class we have to work on a remote server that the school hosts. So far I have made a lot of files on the server and I would like to back them up in case I want to transfer them to my laptop or in case I accidentally delete a directory or make a silly error. I found a tutorial and a script to back up the file and I decided to modify it so that it would determine what directory it’s in (which will be the main user’s) and the cd to the Documents. It also creates the directory Backups if it doesn’t exist. I am still pretty new to this sort of scripting and any additional advice or post links would be greatly appreciated.

Code:

#!/bin/bash
#######################################################
##       Simple backup script..   
## Created by Matthew Brunt: (openblue555@gmail.com)
## Licensed under GNU GPL v3 or later, at your option.
##   http://www.gnu.org/licenses/gpl.html
##
## Further edited by Michael Garrison to backup the 
## directory it is located in and print the contents.
#######################################################

mkdir -p Backup

#Defines our output file
OUTPUT= $( cd Backup && pwd )/backup_$(date +%Y%m%d).tar.gz

#Defines our directory to backup
BUDIR=$( cd Desktop && pwd )
#Display message about starting the backup
echo "Starting backup of directory $BUDIR to file $OUTPUT"

#Start the backup
tar -cZf $OUTPUT $BUDIR

#Checking the status of the last process:
if [ $? == 0 ]; then
        #Display confirmation message
    echo "The file:"
        echo $OUTPUT
    echo "was created as a backup for:"
        echo $BUDIR

        echo ""
    echo "Items that were backed up include:"

    for i in $BUDIR; do
            echo $i
    done
        echo ""
else
    #Display error message message
        echo "There was a problem creating:"
        echo $OUTPUT
    echo "as a backup for:"
    echo $BUDIR
fi

I know that the original script works and it worked until I changed the $OUTPUT variable. I currently get the following result:

./backup.sh
./backup.sh: line 15: /Users/mgarrison93/Backup/backup_20121004.tar.gz: No such file
or directory
Starting backup of directory /Users/mgarrison93/Desktop to file 
tar: no files or directories specified
There was a problem creating:

as a backup for:
/Users/mgarrison93/Desktop

I can see that it is not accepting the file name, but I don’t know how to correct this.

I just tried changing $OUTPUT to /Backups/file-name.tar.gz which I originally had and it works fine. The problem seems to be $( cd Backup && pwd )/backup_$(date +%Y%m%d).tar.gz. Just not sure what is wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:52:53+00:00Added an answer on June 12, 2026 at 6:52 am

    Consider these two entirely different pieces of bash syntax: first, you have the syntax for setting a variable to a value permanently (in the current script),

    <variable>=<value>
    

    and then there is the syntax for running a command with a variable temporarily set to a value ,

    <variable>=<value> <command> <argument> ...
    

    The difference between these two is the space. After the =, once bash runs into an unquoted space, it takes that to mean that the <value> has ended, and anything after it is interpreted as the <command>.

    In this line of your script,

    OUTPUT= $( cd Backup && pwd )/backup_$(date +%Y%m%d).tar.gz
    

    you have a space after OUTPUT=. bash interprets that to mean that OUTPUT is to be (temporarily) set to the empty string, and the rest of the line, i.e. the result of $( cd Backup && pwd )/backup_$(date +%Y%m%d).tar.gz, is a command and arguments to be run while OUTPUT is equal to the empty string.

    The solution is to remove the space. That way bash will know that you’re trying to assign the rest of the line as a value to the variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a utility class that needs to work on a generic Class but
I have a simple Class Hierarchy that I am trying to get to work
I have an app that connects to a remote chat server and then the
I am using a readprocessmemory class and have got it to work for reading
So I have a factory class and I'm trying to work out what the
I am looking to have a portable debug class since i plan to work
I have to make dynamic hashes, so the class example won't work since the
Does css hover work on mobile devices? I have a css hover class which
I have a application with a screen manager class that is causing me some
I have a EJB module in remote Glassfish server and application client in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.