Re: Re: [ilugd] Shell Script:Help Required.

Raj Mathur <[email protected]> Wed, 1 Sep 2004 19:02:32 +0530
Newsgroups gmane.user-groups.linux.delhi.devel
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>>>> "Sandip" == Sandip Bhattacharya <[email protected]> writes:

    Sandip> On Wednesday 01 Sep 2004 5:44 pm, Raj Mathur wrote:
    >> Well, actually you can -- remember the /proc filesystem?  You
    >> can do pretty ghastly things with /proc/self/fd, but the
    >> question is, would you want to?

    Sandip> Dont know about /proc/self/fd myself. How do you use it in
    Sandip> this particular case?

Well, since you ask:

[raju@mail ~]$ cat 1.sh
#!/bin/sh
/bin/ls -l /proc/self/fd/1
exit 0
[raju@mail ~]$ ./1.sh > /tmp/SOMETHING
[raju@mail ~]$ cat /tmp/SOMETHING
l-wx------  1 raju raju 64 Sep  1 18:57 /proc/self/fd/1 -> /tmp/SOMETHING
[raju@mail ~]$

    Sandip> To get the redirection target, you have to get the
    Sandip> parent's (bash) commandline, right?

Nope, /proc/self/fd/[0-9]+ will contain symlinks to the actual files
the various file descriptors are connected to (if they're connected to
files).

Actually extracting the filenames is left as an exercise for the
reader.  It's not trivial -- redirection sort of sucks ;)

Regards,

- -- Raju
- -- 
Raj Mathur                [email protected]      http://kandalaya.org/
       GPG: 78D4 FC67 367F 40E2 0DD5  0FEF C968 D0EF CC68 D17F
                      It is the mind that moves
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQFBNc9lyWjQ78xo0X8RAu09AJwLedac0q4qXw9d83nUgOpyEjD+ogCcC0xA
HNZrccRFsdSolom+kbT4S64=
=xuDx
-----END PGP SIGNATURE-----