From: Geoff Clare on
Janis Papanagnou wrote:

>> 256 represents the return code of grep, indicating that it did not find
>> any text lines matching its search pattern "/etc/".
>
> man 1 grep
>
> Normally, exit status is 0 if selected lines are found and 1 otherwise.
> But the exit status is 2 if an error occurred
>
> man 3 system
>
> The value returned is -1 on error (e.g. fork failed), and the return
> status of the command otherwise. This latter return status is in the
> format specified in wait(2). Thus, the exit code of the command will be
> WEXITSTATUS(status). In case /bin/sh could not be executed, the exit
> status will be that of a command that does exit(127).
>
> man 2 wait
>
> WEXITSTATUS(status)
> evaluates to the least significant eight bits of the return code of the
> child which terminated, which may have been set as the argument to a call
> to exit() or as the argument for a return statement in the main program.
>
>>
>> (actually, I think 256 is the combined return code of the grep command
>> and the shell that was spawned to execute it.)
>
> The shells alone return codes above 128 (resp. 256, depending on the shell)
> to return signal numbers that lead to a process's termination. Just BTW.
>
> I haven't fiddled much with system(3) - the value of 256 looks somewhat
> strange to me

grep's exit status was 1, as per the man page quote above.
The 256 return from system() "represents" this exit status, in
that WEXITSTATUS(256) would evaluate to 1.

The return value from system() (and wait(), waitpid(), etc.) has
to be able to indicate termination by a signal as well as by
exiting. That's why it is in an encoded form, and you have to
use WIFEXITED, WIFSIGNALED, WEXITSTATUS, etc. to decode it.

--
Geoff Clare <netnews(a)gclare.org.uk>

From: Geoff Clare on
John Gordon wrote:

> By default, man pages are displayed via the "more" command, which allows
> only for forward scrolling.

POSIX requires more to be able to move backwards:

Scroll Backward One Screenful

Synopsis:

[count]b
[count]<control>-B

Scroll backward count lines, with a default of one screenful

------

Scroll Backward One Line

Synopsis:

[count]k

Scroll backward count lines.

------

Scroll Backward One Half Screenful

Synopsis:

[count]u
[count]<control>-U

Scroll backward count lines, with a default of one half of the
screen size

------

Search Backward for Pattern

Synopsis:

[count]?[!]pattern<newline>

Display the screenful beginning with the countth previous line
containing the pattern

Although it does also say:

In the case that text is being taken from a non-rewindable stream,
such as a pipe, it is implementation-defined how much backwards
motion is supported.


If you are using a version of more that doesn't support these commands,
try setting PATH=$(getconf PATH):$PATH and you might get conforming
versions of some utilities instead of historical versions.

--
Geoff Clare <netnews(a)gclare.org.uk>



From: jellybean stonerfish on
On Tue, 09 Mar 2010 13:57:41 +0000, Geoff Clare wrote:

> John Gordon wrote:
>
>> By default, man pages are displayed via the "more" command, which
>> allows only for forward scrolling.
>
> POSIX requires more to be able to move backwards:
>
>
> Synopsis:
>
> [count]b
> [count]<control>-B
> [count]k
> [count]u
> [count]<control>-U
> [count]?[!]pattern<newline>
>

On my ubuntu box using a text file, only the 'b', "Scroll backwards one
screenfull" works, but when using 'more' as my pager for man, all of your
examples work. Thank you so much for "fixing" my man program. These
work much better than hitting 'q' and re-invoking man. I feel like such
a dope for not knowing this in the past. It seems like it should be
common knowledge.
From: Jonathan de Boyne Pollard on
>
>
> I changed the directory [...]
>
No, you did not.

> What am I trying to do here?
>
Our collective telepathy is on the fritz, today.

From: Phred Phungus on
Ian Collins wrote:
> Phred Phungus wrote:
>>
>> I don't post to be told that I'm putting forth no effort. Why don't
>> you tell me what I didn't read today,
>
> One of W. Richard Stevens Unix programming books? They will give you
> the background to make better sense of man pages and other documentation.
>

It arrived today. It looks great:

http://www.apuebook.com/


$ ls *
DISCLAIMER fig12.16 fig1.6 fig17.36 fig3.2 fig8.25
fig10.10 fig12.17 fig16.10 fig17.37 fig3.4 fig8.28
fig10.11 fig12.4 fig16.14 fig17.38 fig4.12 fig8.29
fig10.12 fig12.8 fig16.15 fig17.39 fig4.16 fig8.3
fig10.14 fig1.3 fig16.16 fig17.4 fig4.21 fig8.30
fig10.15 fig13.1 fig16.17 fig17.40 fig4.22 fig8.5
fig10.18 fig13.6 fig16.18 fig17.6 fig4.23 fig8.6
fig10.19 fig13.7 fig16.20 fig1.8 fig4.24 fig8.8
fig10.2 fig13.8 fig16.8 fig18.10 fig4.25 fig9.11
fig10.20 fig1.4 fig16.9 fig18.11 fig4.3 figB.1
fig10.22 fig14.1 fig1.7 fig18.12 fig4.8 figB.3
fig10.23 fig14.12 fig17.10 fig18.13 fig4.9 figB.4
fig10.24 fig14.16 fig17.11 fig18.14 fig5.11 figC.1
fig10.25 fig14.17 fig17.12 fig18.15 fig5.12 figC.11
fig10.26 fig14.18 fig17.13 fig18.16 fig5.13 figC.12
fig10.28 fig14.19 fig17.14 fig18.17 fig5.4 figC.13
fig10.29 fig14.29a fig17.15 fig18.18 fig5.5 figC.14
fig10.30 fig14.29b fig17.16 fig18.20 fig6.2 figC.15
fig10.5 fig14.32 fig17.17 fig18.21 fig7.1 figC.16
fig10.6 fig14.5 fig17.19 fig18.22 fig7.11 figC.17
fig10.7 fig14.6 fig17.20 fig1.9 fig7.13 figC.18
fig10.8 fig14.7 fig17.21 fig19.10 fig7.14 figC.20
fig10.9 fig14.9 fig17.22 fig19.11 fig7.16 figC.21
fig1.10 fig1.5 fig17.23 fig19.12 fig7.3 figC.3
fig11.10 fig15.11 fig17.24 fig19.13 fig7.4 figC.4
fig11.11 fig15.12 fig17.25 fig19.17 fig7.9 figC.5
fig11.12 fig15.14 fig17.26 fig19.8 fig8.1 figC.6
fig11.13 fig15.15 fig17.27 fig19.9 fig8.12 figC.7
fig11.14 fig15.17 fig17.28 fig20.3 fig8.13 figC.9
fig11.2 fig15.18 fig17.29 fig2.12 fig8.16 Make.defines.freebsd
fig11.3 fig15.19 fig17.30 fig2.13 fig8.17 Make.defines.linux
fig11.4 fig15.31 fig17.31 fig2.15 fig8.20 Make.defines.macos
fig11.5 fig15.33 fig17.32 fig2.16 fig8.21 Make.defines.solaris
fig12.11 fig15.5 fig17.33 fig3.1 fig8.22 Makefile
fig12.12 fig15.6 fig17.34 fig3.10 fig8.23 README
fig12.13 fig15.7 fig17.35 fig3.11 fig8.24 systype.sh

advio:
catgetmsg.c freebsd.mk macos.mk nonblockw.c solaris.mk
devzero.c linux.mk mcopy.c pendlock.c

call:
call.c escape.c linux.mk macos.mk put.c take.c
call.h freebsd.mk loop.poll.c main.c solaris.mk takeput.c

calld:
calld.h ctlstr.c expectstr.c loop.c sendstr.c ttydial.c
childdial.c debug.c freebsd.mk macos.mk sigchld.c ttyopen.c
cliargs.c devfile.c linux.mk main.c solaris.mk
client.c dialfile.c lock.c request.c sysfile.c

daemons:
freebsd.mk linux.mk macos.mk reread.c solaris.mk
init.c lockfile.c reread2.c single.c

datafiles:
freebsd.mk getpwnam.c linux.mk macos.mk solaris.mk

db:
apue_db.h db.c freebsd.mk linux.mk macos.mk solaris.mk t4.c

environ:
cmd1.c doatexit.c getrlimit.c linux.mk opendata.c testjmp.c
cmd2.c freebsd.mk hello1.c macos.mk solaris.mk

exercises:
asyncsocket.c getpw44bsd.c linux.mk prtime.c sleepus_poll.c
freebsd.mk getpwsvr4.c macos.mk sizepipe.c sleepus_select.c
getlogin.c goodexit.c openmax.c sleep.c solaris.mk

file:
access.c fileflags.c hello.c ls1.c solaris.mk unlink.c
cdpwd.c filetype.c hole.c macos.mk testerror.c zap.c
changemod.c freebsd.mk linux.mk mycd.c uidgid.c
devrdev.c ftw4.c longpath.c seek.c umask.c

include:
apue.h

ipc:
add2.c freebsd.mk myuclc.c pipe4.c solaris.mk tshm.c
add2stdio.c linux.mk pipe1.c popen1.c spipe4.c
fifo1.c macos.mk pipe2.c popen2.c tellwait.c

ipp:
freebsd.mk linux.mk print.c print.h util.c
ipp.h macos.mk printd.c solaris.mk

lib:
bsd_ptyopen.c linux.mk popen.c sendfd.c solaris.mk
bufargs.c linux_ptyopen.c prexit.c servaccept.c spipe.c
cliconn.c lockreg.c prmask.c servlisten.c tellwait.c
clrfl.c locktest.c ptyfork.c setfl.c ttymodes.c
daemonize.c macos.mk readn.c signal.c writen.c
error.c nspipe.c recvfd.c signalintr.c
errorlog.c openmax.c semaph.c sleep.c
freebsd.mk pathalloc.c senderr.c sleepus.c

lock:
deadlock.c freebsd.mk linux.mk macos.mk mandatory.c solaris.mk

mycat:
fgetsfputs.c freebsd.mk getcputc.c linux.mk macos.mk mycat.c
solaris.mk

open:
freebsd.mk linux.mk macos.mk open.c open.h solaris.mk

opend:
client.c linux.mk loop.select.c main.c request.c
freebsd.mk loop.poll.c macos.mk opend.h solaris.mk

opend.fe:
cliargs.c linux.mk main.c request.c
freebsd.mk macos.mk opend.h solaris.mk

open.fe:
freebsd.mk linux.mk macos.mk main.c open.c open.h solaris.mk

proc:
awkexample fork1.c pracct.c system.c tellwait2.c wait1.c
echoall.c fork2.c pruids.c systest1.c test1.c zombie.c
echoarg.c freebsd.mk shell1.c systest2.c times1.c
exec1.c linux.mk shell2.c systest3.c vfork1.c
exec2.c macos.mk solaris.mk tellwait1.c vfork3.c

pty:
driver.c freebsd.mk linux.mk loop.c macos.mk main.c solaris.mk

sess:
freebsd.mk linux.mk macos.mk orphan3.c solaris.mk

signals:
abort.c freebsd.mk mask.c reenter.c sigusr.c solaris.mk system.c
child.c linux.mk read1.c setops.c sleep1.c suspend1.c tsleep2.c
critical.c macos.mk read2.c sigtstp.c sleep2.c suspend2.c

sockets:
bindunix.c findsvc.c linux.mk ruptime.c ruptime-dg.c servlisten.c
bo.c freebsd.mk macos.mk ruptimed.c sendfd2.c solaris.mk
clconn.c initsrv1.c recvfd2.c ruptimed-dg.c sendfd.c spipe.c
cliconn.c initsrv2.c recvfd.c ruptimed-fd.c servaccept.c

std:
conf.c.modified linux.mk makeconf.awk pathconf.sym solaris.mk
sysopt.sym
freebsd.mk macos.mk makeopt.awk pathopt.sym sysconf.sym

stdio:
buf.c freebsd.mk linux.mk macos.mk solaris.mk tempfiles.c tempnam.c

streams:
cliconn.c linux.mk recvfd.c servlisten.c strlist.c
freebsd.mk macos.mk sendfd.c solaris.mk t_isastream.c
isastream.c ptyopen.c servaccept.c spipe.c

termios:
csize.c getpass.c macos.mk t_getpass.c t_ttyname.c
ctermid.c isatty.c settty.c t_isatty.c ttyname.c
freebsd.mk linux.mk solaris.mk t_raw.c winch.c

threadctl:
atfork.c freebsd.mk getenv2.c linux.mk solaris.mk timeout.c
detach.c getenv1.c getenv3.c macos.mk suspend.c

threads:
badexit2.c exitstatus.c macos.mk mutex3.c threadid.c
cleanup.c freebsd.mk mutex1.c rwlock.c
condvar.c linux.mk mutex2.c solaris.mk
$
--
fred