Originally Posted by jpollard
It shouldn't, though shell expansion CAN allow it to work.
Yes it should - POSIX says that
ln [OPTIONS] src1 src1 src3 target-dir
should create link for each src path within that directory - so long as the last term expands to a real directory.
The problem is that the OP doesn't realize the behavior (I think).
Of course 'ln' doesn't handle wildcards directly, but very few utilities do; that's typically the shell's job.
On some systems, ln would check to see if the target existed before creating the link. If the target did not exist, then the link would not be created.
The GNU ln does not check. This can be both good and bad - Good in that it allows you to create symbolic links to files that will exist. Bad in that it allows typographical errors to become links.
That behavior is defined by POSIX; "ln -s left right" or "ln -s lsrc1 lsrc2 lsrc3 rdir" should not check nor care if the left-half file exists when creating a symlink. It's not some GNU-ism and it is important behavior.
Not only is having a link without a real destination valid, and POSIX-ly acceptable - but it's completely unavoidable since the "real" file or parts of it's path may be renamed or unlinked.
The problem is that shell expansion may make multiple targets.
If by "problem" you mean expected and useful behavior - then I agree.
IF the result of the expansion is null you get the parameter unexpanded, which then turns into a bad link.
I *think* you are trying to say this ...
[stevea@luchs Desktop]$ mkdir /tmp/test
[stevea@luchs Desktop]$ cd /tmp/test
[stevea@luchs test]$ ln -s ./foo* ./bar*
[stevea@luchs test]$ ls -l
lrwxrwxrwx 1 stevea stevea 6 Sep 26 20:24 bar* -> ./foo*
which creates a valid link despite the fact that foo\* doesn't exist.
Then we can do depraved thinks like ....
[stevea@luchs test]$ touch foo baz
[stevea@luchs test]$ mkdir somedir
[stevea@luchs test]$ ln -s * somedir
[stevea@luchs test]$ ls -l somedir
lrwxrwxrwx 1 stevea stevea 4 Sep 26 20:31 bar* -> bar*
lrwxrwxrwx 1 stevea stevea 3 Sep 26 20:31 baz -> baz
lrwxrwxrwx 1 stevea stevea 3 Sep 26 20:31 foo -> foo
lrwxrwxrwx 1 stevea stevea 7 Sep 26 20:31 somedir -> somedir
There is nothing BAD about this - so long as we start with a proper understanding that a symlink is a dirent that refers to a PATH that may or may not exist.