spaces in filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting spaces in filename
# 8  
Old 07-20-2010
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:
Code:
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[@]}"

# 9  
Old 07-20-2010
./filer.tar.gz.sh: 2: Syntax error: "(" unexpected
# sh
BusyBox v1.01 (2009.06.07-19:25+0000) Built-in shell (ash)

Thanks any way. it looks like arrays donīt work in this shell.
# 10  
Old 07-20-2010
Yep,
this details are important Smilie

With ash you could try something like this (assuming no newline character(s) in the filenames):

Code:
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
  )

This User Gave Thanks to radoulov For This Post:
# 11  
Old 07-20-2010
For those who are following this thread. Cross reference to Busybox command syntax.

BusyBox - The Swiss Army Knife of Embedded Linux
# 12  
Old 07-20-2010
Quote:
Originally Posted by Lusen
Hello I canīt find an answer to my problem.
I am trying to tar some files with spaces

Code:
#!/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

Try:
Code:
#!/bin/sh

files="'/var/installer/server Config' \
'/var/installer/client user' \
'/var/installer/Svenskt Language' \
'/var/installer/GUI user Plugin' \
'/var/installer/Firefox Plugin'"

eval tar -czvf /tmp/files.tar.gz "$files"

Regards,
Alister

Last edited by alister; 07-20-2010 at 12:52 PM..
# 13  
Old 07-20-2010
Quote:
Originally Posted by alister
Try:
Code:
#!/bin/sh

files="'/var/installer/server Config' \
'/var/installer/client user' \
'/var/installer/Svenskt Language' \
'/var/installer/GUI user Plugin' \
'/var/installer/Firefox Plugin'"

eval tar -czvf /tmp/files.tar.gz "$files"

... and hoping someone does not add something like this to the list of filenames:

Code:
;rm -rf *

# 14  
Old 07-20-2010
Quote:
Originally Posted by radoulov
... and hoping someone does not add something like this to the list of filenames:

Code:
;rm -rf *

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?

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dealing with filename spaces in Perl

The following command to replace text in place in multiple files in a directory is tripping up on filename spaces (Windows environment). I really don't know Perl. find '\\server\directory' | xargs perl -pi -e 's/textA/textB/g'Mike (2 Replies)
Discussion started by: Michael Stora
2 Replies

2. Shell Programming and Scripting

Remove spaces in filename

Hi team, Here's a requirement for me. Here are the list of files i have in a unix directory. W 2 A D_2014.csv W 3 A D_2014.csv W 4 A D_2014.csv /home/kmani00-> uname -a AIX sliyyvxx 1 6 00F613E54C00 /home/kmani00-> The file names has to be without spaces as follows. W2AD_2014.csv... (1 Reply)
Discussion started by: kmanivan82
1 Replies

3. UNIX for Dummies Questions & Answers

Copying files with spaces in the filename in a for loop

Hi all, I've been tangoing with this one for a couple of days now and I'm still not making any progress. Basically I'm trying to match three numbers in a string from a text file with matching numbers in a jpeg, and then copying the results to another folder. Data looks like this: Model:... (4 Replies)
Discussion started by: faceonline
4 Replies

4. Shell Programming and Scripting

Replacing white spaces in filename

Hi; In following code find LOG_DIR -type f | while read filename; do echo $filename; done I want to precede each white space encountered in filename with \ so that when i use $filename for running some commands in do...done,it wont give me an error. will appreciate ur help in this.... (1 Reply)
Discussion started by: ajaypadvi
1 Replies

5. Shell Programming and Scripting

problem with spaces in filename

I have written a script to run ddrescue on a list of files. #!/bin/bash # # A script to rescue data recursively using ddrescue. srcDir=/damaged/hdd/movies/ #the source directory desDir=/new/hdd/movies/ #the destination directory... (2 Replies)
Discussion started by: colsinc
2 Replies

6. Shell Programming and Scripting

ftp var for filename with spaces

Hello all, I am having difficulties writing an ftp script to retrieve a file via get using a variable name to pass the file name. I know the name of the file I am going to retrieve, this file name has embedded spaces and punctuation in the name itself. If I interactively use the get and I... (10 Replies)
Discussion started by: gio001
10 Replies

7. Shell Programming and Scripting

Removing spaces within Filename

Hello, I have a Folder (myfile) which contain the following files: P$12789865KR +N+01+OM+16102009165416.nu P$M1-508962GD +N+01+ALP+14102009094417.nu Is there a sed command(s) that will loop through this folder and remove the spaces that exists in the filename? Any help would be... (7 Replies)
Discussion started by: Fishn
7 Replies

8. Shell Programming and Scripting

List files with spaces in filename

I have a text file containing files in a directory structure i.e. /project/hr/raw/jcpdatav/datav_aug03 /project/hr/raw/jcpdatav/comb8121sep02n /project/hr/raw/jcpdatav/datav_feb04_ons /project/hr/raw/jcpdatav/corpsick_jun06 /project/hr/raw/jcpdatav/jcpjoiners200507... (3 Replies)
Discussion started by: mr_crosby
3 Replies

9. Shell Programming and Scripting

copying files with spaces in the filename

Hi I am having difficulty copying files from one dir to another due to a space in the names of the file with an extension .rtf There are a group of files and the command am using is cp `ls -rt /wlblive/home/whiops/ops/RTFs/*.rtf|head -20` /wlblive/home/jamshed Since the files are... (3 Replies)
Discussion started by: jamshedj
3 Replies

10. Shell Programming and Scripting

Reading a file using sh with spaces in filename

Hi I am trouble parsing through a file with spaces in the filename. I need to grab "supportIDPS/SCM/windows_install/file groups/dds.fgl" and then do a md5sum on it. I am using sh. Any help is appreciated. Here is an example of the input file: 7eedbc9f7902bf4c1878d9e571addf9a ... (4 Replies)
Discussion started by: jekl5
4 Replies
Login or Register to Ask a Question