Thread: using tar command in a shell script

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    31

    using tar command in a shell script

    Hello,
    I am trying to use the tar command in a shell script to create an archive of files.The filenames are stored in another file.The file names are seperated by a whitespace and each filename is within double quotes.
    The file contains file-names in this form :


    "/Windows/E/hari treat/IMG_0679.jpg" "/Windows/E/hari treat/IMG_0678.jpg" "/Windows/E/hari treat/IMG_0673.jpg" "/Windows/E/hari treat/IMG_0669.jpg" "/Windows/E/hari treat/IMG_0675.jpg" "/Windows/E/hari treat/IMG_0680.jpg" "/Windows/E/hari treat/IMG_0676.jpg" "/Windows/E/hari treat/IMG_0672.jpg" "/Windows/E/hari treat/IMG_0674.jpg" "/Windows/E/hari treat/IMG_0681.jpg" "/Windows/E/hari treat/IMG_0671.jpg" "/Windows/E/hari treat/IMG_0670.jpg" "/Windows/E/hari treat/IMG_0677.jpg" "/Windows/E/hari treat/Thumbs.db"

    I tried using tar in the form : tar -cvf 1.tar `cat filenames.txt` .

    tar: "/Windows/E/hari: Cannot stat: No such file or directory

    I guess it is reading filenames only till the whitespace.I tried to escape the whitespace using a \ but still same error.What should I do for tar to work properly?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    tar has an option to read filenames from a file itself.
    One filename per line, possibly without the ""
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shell script basic question
    By PedroTuga in forum Linux Programming
    Replies: 1
    Last Post: 09-09-2006, 03:24 AM
  2. invoking shell script
    By agoel01 in forum C Programming
    Replies: 1
    Last Post: 12-01-2005, 11:37 AM
  3. Game structure, any thoughts?
    By Vorok in forum Game Programming
    Replies: 2
    Last Post: 06-07-2003, 01:47 PM
  4. Running 'exec' twice in one UNIX shell script
    By Zughiaq in forum Tech Board
    Replies: 2
    Last Post: 05-03-2003, 12:04 AM
  5. Arguements with a shell script
    By Doh in forum Linux Programming
    Replies: 1
    Last Post: 11-28-2002, 02:20 PM