Sponsored Content
Top Forums Shell Programming and Scripting Spaces in filenames located in variables in shell. Post 302469591 by Mr.Glaurung on Sunday 7th of November 2010 05:36:55 AM
Old 11-07-2010
Impressive!

It worked! Smilie

... but I got another problem Smilie

So, now it works with the primary copying, but the secondary copying has * in it, and that doesn't work now...

Code:
orig_dir="/Applications/My cool app/$1/"
file_to_copy="$orig_dir$one_single_file"
# This works, yea, thanks!:
cp -v "$file_to_copy" .

file_array=( "lotsoffiles1*" "lotsoffiles2\*" "lotsoffiles3\\*" lotsoffiles4\\\* )
for a_bunch_of_files in ${file_array[@]}
do
	file_to_copy="$orig_dir$a_bunch_of_files"
	cp -v "$file_to_copy" .
done

The second cp (inside the for loop), hates me. As you can see in the file_array I tried lots of different tactics, with these results:

Code:
/Applications/My Cool App/andersdirectory/lotsoffiles1*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles2\*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles3\*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles4\*: No such file or directory.

Can you (or anyone) solve that too?

---------- Post updated at 11:23 AM ---------- Previous update was at 11:18 AM ----------

Noticed that I had forgot "-signs on nr. 4 so I tested:

Code:
file_array=( "lotsoffiles1*" "lotsoffiles2\*" "lotsoffiles3\\*" "lotsoffiles4\\\*" )

Which resulted in:

Code:
/Applications/My Cool App/andersdirectory/lotsoffiles1*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles2\*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles3\*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles4\\*: No such file or directory.

And:

Code:
file_array=( lotsoffiles1* lotsoffiles2\* lotsoffiles3\\* lotsoffiles4\\\* )

which gave:

Code:
/Applications/My Cool App/andersdirectory/lotsoffiles1*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles2*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles3\*: No such file or directory.
/Applications/My Cool App/andersdirectory/lotsoffiles4\*: No such file or directory.

---------- Post updated at 11:36 AM ---------- Previous update was at 11:23 AM ----------

AHA! Smilie

Removed the * in the Array and did:

Code:
cp -v "$file_to_copy"* .

Inside the loop worked wonders.

Thanks for the help! Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

spaces in filenames

I have a problem with the script below #!/bin/sh for vo in `find -maxdepth 1 -type f -regex "^\./*$"` do ls -l "$vo" some other commands done It works fine until `find ...` returns files with spaces. I've tryed to change IFS but haven't succeed Any solutions? (4 Replies)
Discussion started by: Hitori
4 Replies

2. Shell Programming and Scripting

how to handle spaces in filenames

I'm trying to do something like that: for $filename in `ls -1` do some_command $filename done but it doesn't work properly for file names with spaces, for...in splits at spaces. Anyway around? (4 Replies)
Discussion started by: rayne
4 Replies

3. Shell Programming and Scripting

Unix filenames and spaces

I have files on my unix boxes that users have created with spaces. Example: /tmp/project plan ls -l "/tmp/project plan" works fine. $/tmp>ls -l "/tmp/project plan" -rw-r--r-- 1 root other 0 Jan 31 12:32 /tmp/project plan I created a file called test and put just the... (2 Replies)
Discussion started by: x96riley3
2 Replies

4. Shell Programming and Scripting

spaces in filenames, for do

Hi All, I see similar problems in past threads but so far no answers have worked for me. I am trying to write a script which parses a txt file that contains one filename per line, then finds those files on the local disk and copies them to a specified directory. What I have: ... (4 Replies)
Discussion started by: naviztirf
4 Replies

5. Shell Programming and Scripting

How to list filenames with spaces in shell script

Hi, I want to list all the files matching in a directory directory given below Here one of the folder has a space in the path. /MAS02/RMS/WBDev/Krishna/Krishna Mohan/FMSplitByKeyAfterChanges1000075383.fileman.*.txt.out.1000075383.0 The following works from command line... (1 Reply)
Discussion started by: hikrishn
1 Replies

6. Shell Programming and Scripting

spaces in filenames

Hi I hope someone will be able to resolve this little teaser! I am running a script for file in `ls directory` do echo "$file" ...other code here.... done this works fine unless we receive a file with a name which has a space in it ie "filena me" (I know its not good... (8 Replies)
Discussion started by: Bab00shka
8 Replies

7. Shell Programming and Scripting

Moving filenames containing spaces

I want to ftp all the sh files in the directory. Also if any of the file name contains spaces in them, it should be converted to underscores before it is ftped. I wrote the following code below: FILESSH=$(ls /mysh/*.sh) --- FILESH being used here for some other task --- echo "$FILESSH" |... (3 Replies)
Discussion started by: amicon007
3 Replies

8. Shell Programming and Scripting

awk and spaces in filenames

Hey there, this is my first post and I'll try to explain my situation as best I can.Here is a sample of the input file: ADO Sample.h,v ADO Sample 2010-05-21 lyonsb /repository/patents/TSCommon/OpenSource/Dundass/ug6mfc/DataSources/Ado/ADO Sample ADO SampleDoc.h,v ADO SampleDoc 2010-05-21... (3 Replies)
Discussion started by: rodan90
3 Replies

9. Shell Programming and Scripting

White spaces issue with shell variables

Hi all, I've a requirement as below Source file src.txt sample data: A<10 white spaces>B12<5 white spaces>C<17 white spaces> A1<5 white spaces>B22<5 white spaces>C13<17 white spaces> when I'm fetching a record from this file into a shell variable like below: vRec=`head -1 src.txt... (2 Replies)
Discussion started by: madhu_1126
2 Replies

10. Shell Programming and Scripting

Handling filenames with spaces

I'm trying to handle some files with spaces in their name using "" or \ . Like "file 1" or file\ 1. My current confusion can be expressed by the following shell script: #!/bin/bash touch "file 1" "file 2" echo -n "ls: " ; ls echo --- for file in "file 1" "file 2" ; do echo $file... (9 Replies)
Discussion started by: Ralph
9 Replies
All times are GMT -4. The time now is 09:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy