Hello I can�t find an answer to my problem.
I am trying to tar some files with spaces
#!/bin/sh
files="/var/installer/server Config
/var/installer/client user
/var/installer/Svenskt Language
/var/installer/GUI user Plugin
/var/installer/Firefox Plugin"
tar -czvf /tmp/files.tar.gz $files
I have tried escaping the spaces with \ but still errors
tar: /var/installer/server Config
/var/installer/client user
/var/installer/Svenskt Language
/var/installer/GUI user Plugin
/var/installer/Firefox Plugin: No such file or directory
if i use one variable to each file it works
tar -czvf /tmp/files.sat.tar.gz $file1 $file2 $file3
Usage: tar -[czxtvO] [-f TARFILE] [-C DIR] [FILE(s)]...
Create, extract, or list files from a tar file
Options:
c Create
x Extract
t List
Archive format selection:
z Filter the archive through gzip
File selection:
f Name of TARFILE or "-" for stdin
O Extract to stdout
C Change to directory DIR before operation
v Verbose
It's not working, mostly because you're asking it to write to another file extension...namely a gzipped format. Have you looked for the a similar file named .tar?
Otherwise, try the following:
tar czvf - $(find /var/installer -name "* *" -type f ) |gzip -9 - >/tmp/files.tar.gz
it is not the receiving file where the problem is, it is the interpretation from the variable to tar that is failing
this do not work
#!/bin/sh
files="/var/installer/server\ Config
/var/installer/client\ user
/var/installer/Svenskt\ Language
/var/installer/GUI\ user\ Plugin
/var/installer/Firefox\ Plugin"
tar -czvf /tmp/files.tar.gz $files
it don�t find
tar: Config: No such file or directory
tar: /var/installer/server\: No such file or directory
It look likes it do not under stand '\ ' in the file name
but this work
#!/bin/sh
tar -czvf /tmp/files.tar.gz /var/installer/server\ Config /var/installer/client\ user /var/installer/Svenskt\ Language /var/installer/GUI\ user\ Plugin /var/installer/Firefox\ Plugin
You're using options available in GNU tar so I'm assuming you have the bash shell installed. If so, you could use arrays, instead of a scalar variable to store the filenames:
files=(
'/var/installer/server Config'
'/var/installer/client user'
'/var/installer/Svenskt Language'
'/var/installer/GUI user Plugin'
'/var/installer/Firefox Plugin'
)
tar zcfv /tmp/files.tar.gz "${files[@]}"
With ash you could try something like this (assuming no newline character(s) in the filenames):
files="var/installer/server Config
/var/installer/client user
/var/installer/Svenskt Language
/var/installer/GUI user Plugin
/var/installer/Firefox Plugin"
(
IFS='
'
tar czfv files.tar.gz $files
)
I don't mean to be rude, but that's a foolish comment without merit which only serves to engender unwarranted distrust in newbies.
That file list is static, not dynamic and does not blindly eval user provided text. An eval which evals static text is not in any way a problem or a security risk.
However, if unauthorized personnel are editing your scripts, you got problems. Why would anyone bother adding "; rm -fr *" to an eval statement when with the access required to accomplish that they could simply delete the entire script and replace it with a single rm command?