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

  • SEARCH
  • Home
  • 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 9155597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:37:26+00:00 2026-06-17T12:37:26+00:00

In this code, the excludespec variable is expected to match all it substring, but

  • 0

In this code, the excludespec variable is expected to match all it substring, but it appears to evaluate the to the actual files matching it when it is executed, rather than pass its exact representation to the tar command using it.

excludespec=${PWD##*/}\_$USER\_`hostname`.bkcd_backup*

The end result is the archive being created does not match the exclusion list so tar outputs:

tar: .: file changed as we read it

Is the string defining it doing something I don’t know about?

Here is the code:

#!/bin/sh
# bkcd - backup current directory in situ

DMY_M() {
  date +%Y%m%d_%H%M
}

timestring=$(DMY_M)
echo `pwd` - $timestring > .bkcdspec  
filename=${PWD##*/}\_$USER\_`hostname`.bkcd_backup.$timestring.tar.gz    
excludespec=${PWD##*/}\_$USER\_`hostname`.bkcd_backup*
fullexclude="$excludespec"tar.gz    
echo excludespec - $excludespec
echo filename - $filename
echo fullexclude - $fullexclude    
tar -cpzf $filename --exclude=$fullexclude .
rm .bkcdspec
  • 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-17T12:37:28+00:00Added an answer on June 17, 2026 at 12:37 pm

    The usual trick to suppress globbing is to enclose the string in double quotes (when you want backticks or variables to be expanded) or single quotes (when you don’t). So here, you’d eliminate $excludespec and set $fullexclude:

    fullexclude="${PWD##*/}_${USER}_$(hostname).bkcd_backup*.tar.gz"
    

    and use it as:

    tar -cpzf "$filename" --exclude="$fullexclude" .
    

    (Without the double quotes around "$fullexclude", if you happened to have some files named --exclude=...value-of-$fullexclude around, you would get a surprise. You’re unlikely to have such files, but you may as well head off the trouble before it arises.)

    Note that when you’re echoing for debugging, it is also crucial to stop the globbing; again, double quotes:

    echo "filename=$filename"
    echo "fullexclude=$fullexclude"   
    

    Otherwise, echo does glob expansion on the names, confusing you once more.

    Putting those changes together leads to:

    #!/bin/sh
    # bkcd - backup current directory in situ
    
    timestring=$(date +%Y%m%d_%H%M)
    echo "$(pwd) - $timestring" > .bkcdspec
    prefix="${PWD##*/}_${USER}_$(hostname).bkcd_backup"
    filename="$prefix.$timestring.tar.gz"   
    fullexclude="$prefix.*.tar.gz"
    echo "filename - $filename"
    echo "fullexclude - $fullexclude"   
    tar -cpzf "$filename" --exclude="$fullexclude" .
    rm .bkcdspec
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code below allows me to find the word error in all my files
This code works on Linux but fails to match on Windows: if ( preg_match
this code is used to compare the content of 2 text files, but i
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
This code is not pretty, but I want to print out the last generated
This code is a part of a larger code that indexes files, and tokenizes
This code seems to work as expected, populates an array of numbers using a
This code is currently executing about 50 SQL queries: c = Category.objects.all() categories_w_rand_books =
This code streams large files to our users: // Open the file. iStream =
This code works, of course: @x = { :all => { :x => 1,

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.