Re: rpm check script problem



On Monday, Oct 9th 2006 at 16:11 +0100, quoth Dan Track:

=>I've got a script that should check which rpms are installed on the
=>system. Part of the script involves using file descriptors. I'm having
=>trouble understanding these file descriptors and was hoping someone
=>can clarify my mistake. As a simple script I wrote the following:
=>
=>#!/bin/bash
=>$filename=$1
=>$filename1=$2
=>
=>exec 9<&0 < $filename # (1)
=>read rpm
=>echo -e "file1: "$rpm "\c"
=>
=>exec 8<&0 < $filename1 # (2)
=>read rpm1
=>echo -e "file2: "$rpm1 "\c"
=>
=>read rpm2 <&9 # (3)
=>echo -e "file1: "$rpm2 "\c"
=>
=>Now my understanding is that the last read and echo statements should
=>print out what is stored in file descriptor "9" however the script
=>just hangs on the last read. Is there a reason for this? And how do I
=>fix it? I've searched and searched but can't find any reason why this
=>shouldn't work.
=>
=>Thanks
=>Dan

You didn't tell us what you're trying to accomplish.

(1) The exec command without a program to run is used to change
redirection for the duration of the process. So what that does is to dup
channel 9 to be a copy of channel 0. i.e., if you try to read from channel
nine, you'll be reading just as if you were reading from stdin. The
problem is that order is significant. *After* you did the dup you then
said stdin should come from channel 0. If you want stdin to henceforth
come from $filename, you should have said

exec < $filename 9<&0

The next read statment is reading from channel 0 so it reads the first
line of $filename and puts it into the variable rpm.

(2) Again with the exec command. This time we dup channel 0 (which is
already copied into 9) and set the copy into channel 8. The read gives me
the first line of $filename1 and puts it into rpm1. But note that read
ends up not using a duped copy of channel 8. See (1) above.

(3) Now we see the <&9 construct which is really shorthand for 0<&9 which
dups 9 back onto 0 but only for the duration of the read.

Make sense?

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



Relevant Pages

  • Re: using xml to save/open project data
    ... http://www.TransProCalc.org - Free translation project mgmt software ... set filename tk_getOpenfile ... Exec'ing the script you run it as a separate process, your script won't be able to access its vars. ... generating the xml file is easy enough. ...
    (comp.lang.tcl)
  • Re: Help me find 5 mistakes and than solution to thoes mistakes!
    ... > 8:# This script will create links to files from all of the filename ... > 10:# arguments provided on stdin if no filenames provided on command ...
    (Fedora)
  • Re: MIME - scripting and symbol substitutions
    ... This script is creating a text file with a different filename ... symbol called NEWFILENAME (which works, ... MIME from the command line with all options (so normal DCL ...
    (comp.os.vms)
  • Re: virtual server backups
    ... Here is the script. ... 'Save state the virtual machine ... Filename = MyArray) ... Set objVM = Nothing ...
    (microsoft.public.windows.server.general)
  • [NEWS] Light Vulnerable to Remotely Exploitable Arbitrary Code Execution
    ... J.S. Connell has recently discovered that the IRC script for EPIC4 that J. ... S. maintains is vulnerable to an easy remote attack. ... can convince a user to join a channel whose name contains embedded EPIC4 ...
    (Securiteam)