Diffs to the Frequently Asked Questions postings

Steve Hayman sahayman at iuvax.cs.indiana.edu
Thu Jan 3 20:31:24 AEST 1991


Here are the most recent changes to parts 1 and 2 of the
Frequently Asked Questions articles, which have just been
posted.  You can find the full articles elsewhere in
comp.unix.questions.  You can also ftp the most recent version from
iuvax.cs.indiana.edu (129.79.254.192), where it's
"pub/Unix-Questions.part1" and "pub/Unix-Questions.part2".
(IUVax also runs a mail server, for those of you unable to ftp.
 Send the line "HELP" to "mailserv at iuvax.cs.indiana.edu" to get started.)

*** /tmp/,RCSt1a16552	Thu Jan  3 14:27:35 1991
--- part2	Thu Jan  3 14:27:26 1991
***************
*** 1,6 ****
  Subject: Frequently Asked Questions about Unix - with Answers [Monthly posting]
  
! [Last changed: $Date: 90/12/02 23:46:32 $ by $Author: sahayman $]
  
  This article contains the answers to some Frequently Asked Questions
  often seen in comp.unix.questions.  Please don't ask these questions
--- 1,6 ----
  Subject: Frequently Asked Questions about Unix - with Answers [Monthly posting]
  
! [Last changed: $Date: 91/01/03 14:27:19 $ by $Author: sahayman $]
  
  This article contains the answers to some Frequently Asked Questions
  often seen in comp.unix.questions.  Please don't ask these questions
***************
*** 47,58 ****
  	24) How do I tell inside .cshrc if I'm a login shell?
  	25) Why doesn't redirecting a loop work as intended?  (Bourne shell)
  	26) How do I use popen() to open a process for reading AND writing?
! 	27) How do I run 'passwd", 'ftp', 'telnet', 'tip' and other interactive
  	      programs from a shell script or in the background?
  	28) How do I sleep() in a C program for less than one second?
  	29) How can I get setuid shell scripts to work?
  	30) What are some useful Unix or C books?
! 	31) How do I pronounce "vi" , or "!", or "/*", or ...?
  
  
      If you're looking for the answer to, say, question 14, and want to skip
--- 47,60 ----
  	24) How do I tell inside .cshrc if I'm a login shell?
  	25) Why doesn't redirecting a loop work as intended?  (Bourne shell)
  	26) How do I use popen() to open a process for reading AND writing?
! 	27) How do I run 'passwd', 'ftp', 'telnet', 'tip' and other interactive
  	      programs from a shell script or in the background?
  	28) How do I sleep() in a C program for less than one second?
  	29) How can I get setuid shell scripts to work?
  	30) What are some useful Unix or C books?
! 	31) How do I construct a shell glob-pattern that matches all files
! 	    except "." and ".." ?
! 	32) How do I pronounce "vi" , or "!", or "/*", or ...?
  
  
      If you're looking for the answer to, say, question 14, and want to skip
***************
*** 1146,1152 ****
      since that requires cooperation from the processes it is inappropriate
      for a popen()-like library function.
  
! 27) How do I run 'passwd", 'ftp', 'telnet', 'tip' and other interactive
      programs from a shell script or in the background?
  
      The shell itself cannot interact with interactive tty-based programs
--- 1148,1160 ----
      since that requires cooperation from the processes it is inappropriate
      for a popen()-like library function.
  
!     The 'expect' distribution includes a library of functions that a C
!     programmer can call directly.  One of the functions does the
!     equivalent of a popen for both reading and writing.  It uses ptys
!     rather than pipes, and has no deadlock problem.  It's portable to
!     both BSD and SV.  See the next answer for more about 'expect'.
! 
! 27) How do I run 'passwd', 'ftp', 'telnet', 'tip' and other interactive
      programs from a shell script or in the background?
  
      The shell itself cannot interact with interactive tty-based programs
***************
*** 1171,1178 ****
  
      Another solution is provided by the 'pty' program, which runs a
      program under a pty session and was posted to comp.sources.unix,
!     volume 23, issue 31.
  
  28) How do I sleep() in a C program for less than one second?
  
      The first thing you need to be aware of is that all you can specify is a
--- 1179,1209 ----
  
      Another solution is provided by the 'pty' program, which runs a
      program under a pty session and was posted to comp.sources.unix,
!     volume 23, issue 31.  You can also ftp pub/flat/pty-* from
!     stealth.acf.nyu.edu .  A pty-based solution using named pipes
!     to do the same as the above might look like this:
! 
! 	#!/bin/sh
! 	/etc/mknod out.$$ p; exec 2>&1
! 	( exec 4<out.$$; rm -f out.$$
! 	<&4 waitfor 'password:'
! 	    echo "$2"
! 	<&4 waitfor 'password:'
! 	    echo "$2"
! 	<&4 cat >/dev/null
! 	) | ( pty passwd "$1" >out.$$ )
! 
!     Here, 'waitfor' is a simple C program that searches for
!     its argument in the input, character by character.  You can
!     ftp pub/flat/misc-waitfor.c from stealth.acf.nyu.edu .
! 
!     A simpler pty solution (which has the drawback of not 
!     synchronizing properly with the passwd program) is
! 
! 	#!/bin/sh
! 	( sleep 5; echo "$2"; sleep 5; echo "$2") | pty passwd "$1"
  
+ 
  28) How do I sleep() in a C program for less than one second?
  
      The first thing you need to be aware of is that all you can specify is a
***************
*** 1232,1244 ****
  
  	#!/bin/sed -f
  
!     Suppose this script is called `foo', then if you type:
  
  	foo arg1 arg2 arg3
  
      the OS will rearrange things as though you had typed:
  
! 	/bin/sed -f foo arg1 arg2 arg3
  
      There is one difference though: if the setuid permission bit for
      `foo' is set, it will be honored in the first form of the command;
--- 1263,1276 ----
  
  	#!/bin/sed -f
  
!     Suppose this script is called `foo' and is found in /bin,
!     then if you type:
  
  	foo arg1 arg2 arg3
  
      the OS will rearrange things as though you had typed:
  
! 	/bin/sed -f /bin/foo arg1 arg2 arg3
  
      There is one difference though: if the setuid permission bit for
      `foo' is set, it will be honored in the first form of the command;
***************
*** 1247,1253 ****
  
      ----------
  
!     OK, but what if my shell script does NOT start with such a `#!' line?
  
      Well, if the shell (or anybody else) tries to execute it, the OS will
      return an error indication, as the file does not start with a valid
--- 1279,1286 ----
  
      ----------
  
!     OK, but what if my shell script does NOT start with such a `#!' line
!     or my OS does not know about it?
  
      Well, if the shell (or anybody else) tries to execute it, the OS will
      return an error indication, as the file does not start with a valid
***************
*** 1364,1371 ****
  
      Send additions or suggestions to mitch at hq.af.mil .
  
! 31) How do I pronounce "vi" , or "!", or "/*", or ...?
  
      You can start a very long and pointless discussion by wondering
      about this topic on the net.  Some people say "vye", some say
      "vee-eye" (the vi manual suggests this) and some Roman numerologists
--- 1397,1436 ----
  
      Send additions or suggestions to mitch at hq.af.mil .
  
! 31) How do I construct a shell glob-pattern that matches all files
!     except "." and ".." ?
! 
!     You'd think this would be easy.
! 
!     *        Matches all files that don't begin with a ".";
! 
!     .*	     Matches all files that do begin with a ".", but
! 	     this includes the special entries "." and "..",
! 	     which often you don't want;
! 
!     .[^.]*   (Newer shells only)  
! 	     Matches all files that begin with a "." and are
! 	     followed by a non-"."; unfortunately this will miss
! 	     "..foo";
! 
!     .??*     Matches files that begin with a "." and which are
! 	     at least 3 characters long.  This neatly avoids
! 	     "." and "..", but also misses ".a" . 
! 
!     
!     Many people are willing to use .??* to match all dotfiles
!     (or * .??* to match all files) even though that pattern doesn't
!     get everything - it has the advantage of being easy to type.
!     If you really do want to be sure, you'll need to employ
!     an external program or two and use backquote substitution.
!     This is pretty good:
! 
!     `ls -a | sed -e '/^\.$/d' -e '/^\.\.$/d'`
  
+     but even it will mess up on files with newlines in their names.
+ 
+ 32) How do I pronounce "vi" , or "!", or "/*", or ...?
+ 
      You can start a very long and pointless discussion by wondering
      about this topic on the net.  Some people say "vye", some say
      "vee-eye" (the vi manual suggests this) and some Roman numerologists
***************
*** 1596,1602 ****
  | broken line	EBCDIC has two vertical bars, one solid and one broken.
  ~ enyay		from the Spanish n-tilde
  () nil		LISP
- 
  -- 
  Steve Hayman    Workstation Manager    Computer Science Department   Indiana U.
  sahayman at iuvax.cs.indiana.edu                                    (812) 855-6984
--- 1661,1666 ----



More information about the Comp.unix.questions mailing list