[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: for i in *



Hans <hansfong@zonnet.nl> writes:

> I still don't understand the proper syntax for this: I want to process
> multiple files, e.g. symlinking a bunch or converting graphics.
> 
> for i in *;do 'ln -s $i /home/newdir/$i';done
> 
> won't work. 

This tries to execute the _command_ 'ln -s $i /home/newdir/$i' and not
the command 'ln' with the parameters -s, $i, and /home/newdir/$i;

The proper syntax for this loop would be:

for i in *; do ln -s $i /home/newdir/$i; done

which would create symlinks in the directory /home/newdir pointing to
the (non-hidden) files in the current directory.

> Could someone please explain the rules for doing stuff like this, e.g. when
> to use quotes and what quotes, when to write files to a new file and
> renaming them back.

There are no special quotations needed for the loop. The syntax is:

          for NAME [in WORDS ...]; do COMMANDS; done

(from bash's info pages, package bash-doc)

You also wouldn't write

$ 'ls -a'

if you want to execute the command ls, with parameter -a.

Have you searched in the bash manual (info pages, man pages)? There's
also a section about quotations.

        hth,
	moritz
-- 
Moritz Schulte <moritz@chaosdorf.de> http://www.chaosdorf.de/moritz/
Debian/GNU supporter - http://www.debian.org/ http://www.gnu.org/
GPG fingerprint = 3A14 3923 15BE FD57 FC06  B501 0841 2D7B 6F98 4199



Reply to: