10-08-2008
Problem's solution
I never did truly understand "exactly" what it was about how I was using variables that was the problem but I found a work around, so to speak.
First if you want to use a variable to hold a "bad" file name, or one with unusual characters in it, to be used with the cp command -- then process the filename the minimum amount possible. I was processing the file name to create a new name, then I had to process it some more to undo the first processing so I could get the original name back. Bad idea, something happened to the filename while doing all that processing and I could never get it back to exactly what it was before... So I set out to minimize the processing of the filename to be used in the variable used to copy the old filename to the new filename.
Second, bash does its own processing of special characters and spaces when the cp command is run. Do not try to help it by adding escape characters (backslashes) to the variable. You have to deliver the name to the variable "exactly" as it appears when you use ls to display it. Then if the variable is quoted with double quotes, then bash can properly process it -- no matter what characters are in the file name.
Even though you can type the filename in by hand and add backslashes to the name and when you run the cp command from the script, it will work -- that ability will not transfer to a variable. Putting that same text with backslashes into a variable does not work because the variable does some processing "before or as" it expands the variable when the cp command is run. That "extra" processing produces something that is different than what was put in the variable, usually it adds backslashes and when it does, it does not match the "real" filename and can not copy it to the new filename.
Here is how I was originally processing the filenames. I was creating a list of filenames and storing them as a variable. Because the variable "fed" a for loop, I had to remove any spaces before I used the variable (for loops will not work with spaces in the filenames). I created the "filename list" variable and converted the spaces to % at the same time. I then separated the filenames into the basename and extension and stored them in variables. When I finished I reassembled this to get the original filename's basename and extension and removed the %s that I had inserted previously
This was too much processing. I ignored the KISS rule. The final cure was use the entire original filename with the % added -- as provided by the for loop -- instead of breaking it into basename and extension and having to reassemble all that back into the original file name. This allowed me to use the original filename with no processing other than removing the % symbol which I did at the same time I reassigned it to the final variable used by the cp command. Then all I had to do was quote the variable and everything worked.
My filename repair script works perfectly now and can repair filenames with leading and trailing spaces, backslashes, single quotes and any other characters that I have tried so far except the % symbol. There are two problems with % in the filename. When they are assigned to the variable storing the filenames bash turned % into %%, then the script turned all spaces into % and things went downhill from there. I decided to leave things alone and not try to process files with % in them, (files with % in them are very rare anyway).
I hope this makes sense, and can help someone in the future.
Thanks for everyone's help.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi I am going to migrate our datawarehouse system from HP Tru 64 Unix to the Red Hat Linux.
Inside the box, it is running around 40 cron jobs; inside each cron job, it is calling other shell script files, and the shell script files may again call other shell script files or ctl files(for... (1 Reply)
Discussion started by: franksubramania
1 Replies
2. Shell Programming and Scripting
Dear other forum members,
I'm writing a script for my homework, but I'm scratching all over my head and still can't figure out what I did wrong. Please help me. I just started to learn about bash scripting, and I appreciate if anyone of you can point out my errors. I thank you in advance.
... (3 Replies)
Discussion started by: ilove2smoke
3 Replies
3. Shell Programming and Scripting
I am trying to FTP files to a Windows server through my Linux machine. I have setup the file transfer with no problems but am having problem deleting those files from the Linux box. My current non-working solution is below. Any ideas, anyone?? :wall: Please be gentle, I'm fairly new to this... (4 Replies)
Discussion started by: jmalfhs
4 Replies
4. Shell Programming and Scripting
Hi,
I am new to shell scripting.Please help me on this.I am using solaris 10 OS and shell i am using is
# echo $0
-sh
My requirement is i have source file say makefile.I need to extract files with extensions (.c |.cxx |.h |.hxx |.sc) from the makefile.after doing so i need to check whether... (13 Replies)
Discussion started by: muraliinfy04
13 Replies
5. Shell Programming and Scripting
I am new to Shell Scripting and need some help.
The following batch job has been failing for me due to the .nfsxxx files in use. I need to know how to modify the following script to exclude the .nfsxxx files so this batch job will not fail on me. I have done lots of googling and keep coming back... (2 Replies)
Discussion started by: kimberlyg2007
2 Replies
6. Shell Programming and Scripting
HI,
I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this:
1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies
7. Shell Programming and Scripting
#!/bin/bash
#
name=$1
type=$2
number=1
for file in ./**
do
if
then
filenumber=00$number
elif
then
filenumber=0$number
fi
tempname="$name""$filenumber"."$type"
if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies
8. Shell Programming and Scripting
Hi,
Can anyone help me how to convert a .csv file to a .pdf file using shell script
Thanks (2 Replies)
Discussion started by: ssk250
2 Replies
9. Shell Programming and Scripting
Hi,
In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this?
I am using #!/bin/ksh
For eg: sftp user@host <<EOF
cd /path
get *.txt
rename *.txt *.txt.done
... (7 Replies)
Discussion started by: jhilmil
7 Replies
10. Shell Programming and Scripting
Hi,
Very good wishes to all!
Please help to provide the shell script for generating the record counts in filed wise from the .csv file
My question:
Source file:
Field1 Field2 Field3
abc 12f sLm
1234 hjd 12d
Hyd 34
Chn
My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies
uudemon(4) Kernel Interfaces Manual uudemon(4)
NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool
directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons
SYNOPSIS
These shell scripts reside in the following directory:
/usr/lib/uucp
DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove
the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file.
This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the
results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or
root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com-
mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This
script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour
script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script.
FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file.
RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1)
Files: /usr/lib/uucp delim off
uudemon(4)