LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash with Special Characters not copying (https://www.linuxquestions.org/questions/linux-software-2/bash-with-special-characters-not-copying-4175594173/)

JJJCR 11-24-2016 07:51 AM

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.

wpeckham 11-24-2016 12:37 PM

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?

goumba 11-24-2016 02:10 PM

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.

JJJCR 11-24-2016 04:43 PM

Quote:

Originally Posted by wpeckham (Post 5634230)
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.

JJJCR 11-24-2016 04:44 PM

Quote:

Originally Posted by goumba (Post 5634242)
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.

Emerson 11-24-2016 04:51 PM

Maybe this helps.

goumba 11-24-2016 06:39 PM

Quote:

Originally Posted by JJJCR (Post 5634272)
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.

syg00 11-24-2016 09:07 PM

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 ?.

pan64 11-25-2016 12:45 AM

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...

JJJCR 12-07-2016 02:44 AM

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.

wpeckham 12-07-2016 11:46 AM

Quote:

Originally Posted by JJJCR (Post 5639005)
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.

c0wb0y 12-07-2016 12:10 PM

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/"

JJJCR 12-08-2016 02:48 AM

Quote:

Originally Posted by c0wb0y (Post 5639182)
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.

pan64 12-08-2016 02:53 AM

"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?

c0wb0y 12-08-2016 10:23 AM

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/
-----



All times are GMT -5. The time now is 03:02 AM.