If the file is a link to the LINUX OS

I am trying to check if a symlink exists from a KornShell (ksh) script using the command "-h file_name". This works well on HP boxes.

Not sure if this is the right option for Linux, AIX, or Solaris.

Any understanding of this?

+3
source share
4 answers

-his part of the POSIX spec ; it should work everywhere, which is vaguely reasonable.

According to man teston Mac OS X:

     -h file True if file exists and is a symbolic link. This operator
                   is retained for compatibility with previous versions of
                   this program. Do not rely on its existence; use -L instead.

-L , , -, -h , -L.

+6

- linux-, (bash - ):

lrwxrwxrwx 1 mule mule 37 Feb 27 09:43 mule.log -> /home/mule/runtime/mule/logs/mule.log
[mule@emdlcis01 ~]$ if [[ -h mule.log ]]; then echo "mule.log is a symlink that exists" ; fi
mule.log is a symlink that exists

man test, , .

+5

- , "" . , . , , , , , "expr" "[" . expr /bin. Solaris , ksh93 [ ( man-, , ). , ksh expr [.

% truss -f -texec /bin/ksh '[ -h /home ]'
26056:  execve("/usr/bin/ksh", 0x08047708, 0x08047714)  argc = 2
26056:  execve("/usr/bin/ksh93", 0x08047708, 0x08047714)  argc = 2
26056:  execve("/usr/bin/amd64/ksh93", 0x08047704, 0x08047710)  argc = 2

% truss -f -texec /bin/ksh '/bin/expr -h /home ]'
26058:  execve("/usr/bin/ksh", 0x08047700, 0x0804770C)  argc = 2
26058:  execve("/usr/bin/ksh93", 0x08047700, 0x0804770C)  argc = 2
26058:  execve("/usr/bin/amd64/ksh93", 0x080476FC, 0x08047708)  argc = 2
26058:  execve("/bin/expr", 0x00418360, 0x00418398)  argc = 4
+1

:

    if [ -h filename ] 
OR
    ls -ltr | grep filename | grep ^l

$? 0, , , .

0

Source: https://habr.com/ru/post/1705731/


All Articles