PLEX86  x86- Virtual Machine (VM) Program
 Plex86  |  CVS  |  Mailing List  |  Download  |  Linux  |  Newsgroups

Spaces in UNIX Filenames 'Bad


Your Ad Here

Your Ad Here

No such file or directory" in Batch mode 7354
Hi Roger, Roger Leigh That would be something for my employer to decide. I will...

You may like to know in the future that **filename expansion** is the last expansion Bash performs on the text of a command, after word splitting.

This means that you can do:

for filename in * .* do newname=${filename--} if "$newname" != "$filename" then n=1 suff= while -e "$newname$suff" do $suff=$n n=$((n+1)) done mv "$filename" "$newname$suff" fi done

This code expands the asterisk to a list of file names, and sets "filename" to each file name in turn, without breaking up filenames that contain spaces. The dot-asterisk expands to the names of files with a leading dot.

missing library o3
I was trying to compile gtk+ and friends the othe night (never finished -- too many dependencies), and now a few things won't run. They all give...

Notice how all subsequent use of the variable "filename" is enclosed in quotes, because the *parameter and variable expansion" is done before work splitting, and we don't want the file names to be split. (The buttignment to newname is a special case, that is also not split, without need for qoutes.)

Then it creates a new name in the variable "newname", irrespective of whether the file name contains spaces. If it does not contain spaces, the variable "newname" will be equal to "filename".

No such file or directory" in Batch mode 7353
BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Have you tried the same under sh-bash or any POSIX shell? AFAIK this is a fairly ancient...

Then it checks if the new name actually differs from the old name. If not, there were no spaces in the old name, and nothing needs to be done.

If there are differences, it checks if a file already exists with the new name. If so, it adds a numeric suffix to the new file name. It repeates the test until it finds a name that is not in use.

Then finally it renames the file

The script could still fail, if the number of files in the directory is so large that the command line length of the shell is exceeded. I am not sure, though, if there is any command line length limit (except memory availability) for *internal* bash commands. After all, "for" statements are not executed using an execve system call.

Another possibility is

ls -A while read filename do ... done

The "read" builtin command splits the input at newlines. If there are more than one variable names as arguments, the input line is split in as many words, the last word being "the rest of the line". Multiple contiguous spaces in the "rest of the line" are preserved.

In this way there is not risk of running out of command line space. This method can fail if there are file names containing newline characters.

-Enrique



Your Ad Here

List | Previous | Next

missing library o3

Linux groups from Newsgroups

The #1 Usenet Provider on the Internet

How to Parbreastions the disk to install FC4 7349