LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-24-2016, 07:51 AM   #1
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Cool Bash with Special Characters not copying


Hi guys, need your help on this got a script that read files and put the it into a variable but the path has a special character "#" and therefore not copying.

Any help is greatly appreciated.

Thank you.

Quote:

#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do


cp "/usr/dfiles/$line/Tasks/#msgs/*.eml" "/mnt/NAS/Tasks1/$line/"

done < "$1"


chmod +x xx.sh
./xx.sh filename.txt

I had tried this methods below but no joy:

cp "/usr/dfiles/$line/Tasks/?msgs/*.eml" "/mnt/NAS/Tasks1/$line/"
cp "/usr/dfiles/$line/Tasks/\#msgs/*.eml" "/mnt/NAS/Tasks1/$line/"
cp "/usr/dfiles/$line/Tasks/\?msgs/*.eml" "/mnt/NAS/Tasks1/$line/"
cp "/usr/dfiles/$line/Tasks/\*msgs/*.eml" "/mnt/NAS/Tasks1/$line/"
Always no such file or directory.
 
Old 11-24-2016, 12:37 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,631

Rep: Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696
Have you tried anything like
Code:
cp "/usr/dfiles/$line/Tasks/"'#msgs'"/*.eml" "/mnt/NAS/Tasks1/$line/"
but perhaps more to the point why do you have folder names with the '#' character in them?

I forgot to ask, have you verified that the files *.emp exist in those folders?

Last edited by wpeckham; 11-24-2016 at 01:13 PM.
 
Old 11-24-2016, 02:10 PM   #3
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Is the msgs folder the only sub folder of Tasks? If so: try to copy the path manually, use tab completion. Not only will bash complete the name, but it will do so while properly escaping it, so you can take note of what you yourself need to do to copy that folder's contents.
 
Old 11-24-2016, 04:43 PM   #4
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Cool

Quote:
Originally Posted by wpeckham View Post
Have you tried anything like
Code:
cp "/usr/dfiles/$line/Tasks/"'#msgs'"/*.eml" "/mnt/NAS/Tasks1/$line/"
but perhaps more to the point why do you have folder names with the '#' character in them?

I forgot to ask, have you verified that the files *.emp exist in those folders?
That's the default path of the application it has "#", yes the *.eml exists on the folder it has hundreds of them.

I tried the method you give, no joy. Thanks.
 
Old 11-24-2016, 04:44 PM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Post

Quote:
Originally Posted by goumba View Post
Is the msgs folder the only sub folder of Tasks? If so: try to copy the path manually, use tab completion. Not only will bash complete the name, but it will do so while properly escaping it, so you can take note of what you yourself need to do to copy that folder's contents.
Thanks, if really no choice I have to do it manually. But I think I will do it for quite a few hours because there's a lot.
 
Old 11-24-2016, 04:51 PM   #6
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~amd64
Posts: 7,661

Rep: Reputation: Disabled
Maybe this helps.
 
Old 11-24-2016, 06:39 PM   #7
goumba
Senior Member
 
Registered: Dec 2009
Location: New Jersey, USA
Distribution: Fedora, OpenSUSE, FreeBSD, OpenBSD, macOS (hack). Past: Debian, Arch, RedHat (pre-RHEL).
Posts: 1,335
Blog Entries: 7

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by JJJCR View Post
Thanks, if really no choice I have to do it manually. But I think I will do it for quite a few hours because there's a lot.
No, but if none of the other suggestions help, just to try it with one file, and maybe you'll learn how bash would like that path escaped.
 
Old 11-24-2016, 09:07 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Do some testing to determine if source (as you seem to presume) is actually the problem.
Do all those "$line" directory levels exist at the target ?.
 
Old 11-25-2016, 12:45 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
I suggest you to add set -xv at the beginning of your script and you will see what's happening. It will not fix itself, just will give you debug info. Probably helps...
 
Old 12-07-2016, 02:44 AM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Hi guys, thanks for all the replies never had the time to troubleshoot or try something. The deadline was approaching, to get the thing done I did it for 6 hours.
 
Old 12-07-2016, 11:46 AM   #11
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,631

Rep: Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696Reputation: 2696
Quote:
Originally Posted by JJJCR View Post
Hi guys, thanks for all the replies never had the time to troubleshoot or try something. The deadline was approaching, to get the thing done I did it for 6 hours.
Ouch!

Admire your dedication, but when you have time I would play with the tools to ensure you know ways to get it done quicker in the future.

I am trying to think of anything I do for 6 hours since I left the military, and got nothing. Even sleep is in shifts, and I rarely get 6 hours. Wow.
 
Old 12-07-2016, 12:10 PM   #12
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421

Rep: Reputation: 74
Can you try this:

Code:
cp /usr/dfiles/$line/Tasks/'?msgs'/*.eml" "/mnt/NAS/Tasks1/$line/"
-----
Or,

Code:
cp /usr/dfiles/$line/Tasks/*msgs/*.eml "/mnt/NAS/Tasks1/$line/"
 
Old 12-08-2016, 02:48 AM   #13
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,150

Original Poster
Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Cool

Quote:
Originally Posted by c0wb0y View Post
Can you try this:

Code:
cp /usr/dfiles/$line/Tasks/'?msgs'/*.eml" "/mnt/NAS/Tasks1/$line/"
-----
Or,

Code:
cp /usr/dfiles/$line/Tasks/*msgs/*.eml "/mnt/NAS/Tasks1/$line/"
I tried those commands that you posted but with no joy.
 
Old 12-08-2016, 02:53 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
"no joy" is not a usable answer. It does not give any information about what did you really try, what's happened, what was the result, what went wrong - therefore we cannot give you any hint, just this one: "better luck next time".
Have you tried already set -xv?
 
Old 12-08-2016, 10:23 AM   #15
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 421

Rep: Reputation: 74
Quote:
I tried those commands that you posted but with no joy.
Pretty much what pan64 said.

Anyhow, I spotted one mistake with my post. I left an extra " there.

How about this:
Code:
cp /usr/dfiles/$line/Tasks/'?msgs'/*.eml /mnt/NAS/Tasks1/$line/
-----
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Special characters in bash robertjinx Linux - Server 4 06-21-2016 07:45 AM
How do I replace special characters in a string within a bash script? rhaup0317 Linux - Newbie 2 06-03-2008 11:56 AM
Copying files with special characters cornish Linux - Newbie 13 12-21-2007 11:22 AM
How to rename file while copying - and remove special characters corporal79 Linux - General 3 10-11-2007 04:16 PM
bash and filenames with special characters CoolAJ86 Programming 2 03-09-2005 02:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration