Reason why some commands need escaped-characters and other not


 
Thread Tools Search this Thread
Operating Systems Solaris Reason why some commands need escaped-characters and other not
# 1  
Old 10-18-2010
Question Reason why some commands need escaped-characters and other not

Hi, this is my first post and hope to make some contribution soon.

I'm still learning the basics of UNIX and Linux and BASH. Thus my need to understand the subject at hand. I don't have a problem with technical detail, so hit me Smilie


I have a script where two commands use the contents of a text file (containing path and file names) to perform actions on those files.
My question is this:
One of the commands needs to have the equals-signs and commas escaped (in the file names) but the other command doesn't. Why is this?

Thanks in advance.

Script file in progress:

Code:
#Move a limited number of files including their folder structure
find ./ -type f -print | head -n 500  > listoffiles.txt

This next command does NOT need to have the commas and equals signs escaped
Code:
# (this command doesn't need to have the equals and commas escaped
cat listoffiles.txt | cpio -pdm /app/facts/sm/ftp/utran_rbs/

Code:
# Find and replace text in files
# replace comma and equals sign , =  with \,  and \=   we have to escape the escape sign so \, becomes \\, and \= becomes \\=
find . -name 'listoffiles.txt' | xargs perl -pi -e 's/=/\\=/g' 
find . -name 'listoffiles.txt' | xargs perl -pi -e 's/,/\\,/g'

This next command DOES need to have the commas and equals signs escaped
Code:
# Remove the files after they have been copied (maybe I need some kind of automated check here. At the moment I do a manual count of the files in the target folder to see if the files were copied
# (this command does need to have the equals and commas escaped
cat listoffiles.txt | xargs /bin/rm -f


small extract of some of the file names contained in listoffiles.txt:

before change:
Code:
./SubNetwork=RBRNC1/MeContext=U0004-Nedbank_Gardens/A20101015.0945+0200-1000+0200_SubNetwork=ONRM_RootMo,SubNetwork=RBRNC1,MeContext=U0004-Nedbank_Gardens_statsfile.xml
./SubNetwork=RBRNC1/MeContext=U7147-Victory_Park_CC/A20101015.0945+0200-1000+0200_SubNetwork=ONRM_RootMo,SubNetwork=RBRNC1,MeContext=U7147-Victory_Park_CC_statsfile.xml


After Change:
Code:
./SubNetwork\=RBRNC1/MeContext\=U0004-Nedbank_Gardens/A20101015.0945+0200-1000+0200_SubNetwork\=ONRM_RootMo\,SubNetwork\=RBRNC1\,MeContext\=U0004-Nedbank_Gardens_statsfile.xml
./SubNetwork\=RBRNC1/MeContext\=U7147-Victory_Park_CC/A20101015.0945+0200-1000+0200_SubNetwork\=ONRM_RootMo\,SubNetwork\=RBRNC1\,MeContext\=U7147-Victory_Park_CC_statsfile.xml

P.S. I'm trying to develop a script, so if anyone has suggestions for improvement, they will be very welcome. Alternatively I can post this as a separate thread for clarity's sake.

The script is intended to:
1) take a folder (A) with a very large number of files and subfolders and move the files to another folder (B) while keeping the folder structure.
2) The subfolders might exist in the target folder, so mv did seem to like that
3) Move a specific number of files at a time so as not to overwhelm the processing of the files in the target folder.
4) Process the next source folder and repeat the process

Last edited by doublefrangelic; 10-18-2010 at 10:09 AM.. Reason: Cleaned up code formatting for readability
# 2  
Old 10-18-2010
Quote:
Originally Posted by doublefrangelic
One of the commands needs to have the equals-signs and commas escaped (in the file names) but the other command doesn't. Why is this?
There is neither a comma nor an equal sign appearing in the first command line so obviously no need to escape them within it.
# 3  
Old 10-18-2010
Quote:
Originally Posted by jlliagre
There is neither a comma nor an equal sign appearing in the first command line so obviously no need to escape them within it.

The commas and equals signs appear in the file names and folders, and these appear within the listoffiles.txt input file

apologies, I only noticed now that the comment
# (this command does need to have the equals and commas escaped
preceded the wrong line. It is meant to be before the rm command.

---------- Post updated at 01:49 PM ---------- Previous update was at 01:46 PM ----------

I have edited the script in my post, and it now appears as it should be.

The question remains

Thank you

---------- Post updated at 02:20 PM ---------- Previous update was at 01:49 PM ----------

OK, my apologies, I have not solved the problem but my question is irrelevant.

I discovered that the problem I am experiencing occurs whether or not the file names are escaped.

The filenames are corrupted in the results of the rm command-line and many were corrupted close to the equals signs and commas
The issue occurs intermittently so I assumed it had something to do with escaping the characters.
Now to figure out why.. thanks Anyway for the assistance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[BASH] Getting a semi-tailing backslash when passing (escaped) variables to script

Heyas Figured me had a 'typo' in tui-conf-set, i went to fix it. Now, i also figured, it might be nice to have tui-conf-set report (to console, not only exit code) wether it could save the variable to the file or not. This said, I appended this code: (the tui-title and tui-echo lines are... (3 Replies)
Discussion started by: sea
3 Replies

2. UNIX for Dummies Questions & Answers

Using read with escaped variables

Not sure if this is possible, but I'm trying to read in a variable that needs to have its escape backslashes intact. So the person who enters the actual value does not have to type any \ characters. Example: read list X1000\ filecab.txt echo "$list" In this case the \ needs to be... (3 Replies)
Discussion started by: newbie2010
3 Replies

3. Shell Programming and Scripting

Parsing special characters from variable commands

Hi, I am fairly new to unix scripting and recently tasked with some reporting scripts. The reporting checks several batch jobs and this is quite iterative. Now I am trying to minimize script effort and maximize reusability as there are only slight nuances in the repetitive tasks. For... (3 Replies)
Discussion started by: joeniks
3 Replies

4. Shell Programming and Scripting

Regex:search/replace but not for escaped character

Hi Input: - -- --- ---- aa-bb-cc aa--bb--cc aa---bb---cc aa----bb----cc Output: . - -. -- aa.bb.cc (7 Replies)
Discussion started by: chitech
7 Replies

5. UNIX for Dummies Questions & Answers

Display file with escaped color codes

Hi, I have a file containing color codes: Fri May 25 17:13:04 2012: Starting MTA: exim4^ Loading cpufreq kernel modules...^How can I display it colorized on a linux terminal? (4 Replies)
Discussion started by: ripat
4 Replies

6. Shell Programming and Scripting

hidden characters added to commands

Hello everybody. Im really new in shell scripting. Im working with RedHat 4. I have begin to do some scripts to test the posibilitys but Im fancing a disturbing problem. some times the lines that I write add the return character or end-of-file ascii character to the command or argument tha... (2 Replies)
Discussion started by: josebenitez
2 Replies

7. Shell Programming and Scripting

Editing long records with characters that need to be escaped.

Hi all, I'm new in unix scripting and I've a problem with a script... :confused: I need to read a file, add some fields in the records, and write them in another file, but even when I simply read and write the records, the shell interprets some caracters and the result is that the records... (5 Replies)
Discussion started by: Macs_Linux
5 Replies

8. Shell Programming and Scripting

problems with sed and bash. Escaped characters ?

Hi, I'm writing a long script for bash (on RHEL 5.0) to execute many commands. So, my idea is to create a function to deal with error checking and logging (see ceckoutput() below). This works with all commands except for sed. I think it may be a problems with escaped characters. So I did the... (4 Replies)
Discussion started by: macL
4 Replies

9. Shell Programming and Scripting

Echo escaped \c in SH Shell Any Idea

Hi All, I have got an echo statement with "\c" in it to avoid getting into a newline. Ths script is using #!\bin\sh Any idea what could make it to escape "\c" (4 Replies)
Discussion started by: asami
4 Replies

10. Post Here to Contact Site Administrators and Moderators

angle brackets should be escaped automatically

I think that HTML code within posts should be turned off -- the vB Code can provide all the features we need. Then, you should modify the program to automatically escape any angle brackets, so that < gets translated to < and > gets translated to > I see a lot of people garble their posts... (4 Replies)
Discussion started by: PxT
4 Replies
Login or Register to Ask a Question

Featured Tech Videos