> I'm not sure whether this is a bug or a feature.
> If I create a symlink to a directory
> 
> > ls
> code  code2
> > ln -s code test
> 
> and then try to relink it
> > ln -sf code2 test
> 
> In linux using gnu-fileutils a link is created in code called code2
> pointing to code2. On a Compaq Tru64 machine, the standard ln gives an
> error message. I assume one is doing the wrong thing? What does the POSIX
> standard say?

http://www.unix-systems.org/single_unix_specification_v2/xcu/ln.html

[Just the pertinent stuff.]

SYNOPSIS
  ln [-f] source_file target_file
  ln [-f] source_file... target_dir

DESCRIPTION

  In the first synopsis form, the ln utility will create a new
  directory entry (link) for the file specified by the source_file
  operand, at the destination path specified by the target_file
  operand. This first synopsis form is assumed when the final operand
  does not name an existing directory; if more than two operands are
  specified and the final is not an existing directory, an error will
  result.

  In the second synopsis form, the ln utility will create a new
  directory entry for each file specified by a source_file operand, at a
  destination path in the existing directory named by target_dir.

  The corresponding destination path for each source_file will be the
  concatenation of the target directory pathname, a slash character, and
  the last pathname component of the source_file. The second synopsis
  form will be assumed when the final operand names an existing
  directory.
[...]

If the target is a directory (symlink or not) then the second form
applies.  Typically to make this case completely unabiguous most
scripts place a trailing slash on the end to show that the last
parameter is a directory.  If it is not then the command must fail.

Example:
  ln -sf file testdir/

In the case where there is no slash it depends on the context.
I recommend avoiding that case if possible.
  ln -sf file file_or_dir


Bob Proulx

  • ln bug? Jeremy Sanders
    • Bob Proulx

Reply via email to