POSIX Commands 353 K
User Manual: 353
Open the PDF directly: View PDF .
Page Count: 918
Download | |
Open PDF In Browser | View PDF |
© Siemens Nixdorf Informationssysteme AG 1995 POSIX Commands Edition May 2009 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.vor Comments… Suggestions… Corrections… The User Documentation Department would like to know your opinion on this manual. Your feedback helps us to optimize our documentation to suit your individual needs. Feel free to send us your comments by e-mail to: manuals@ts.fujitsu.com Certified documentation according to DIN EN ISO 9001:2000 To ensure a consistently high quality standard and user-friendliness, this documentation was created to meet the regulations of a quality management system which complies with the requirements of the standard DIN EN ISO 9001:2000. cognitas. Gesellschaft für Technik-Dokumentation mbH www.cognitas.de Copyright and Trademarks Copyright © Fujitsu Technology Solutions GmbH 2009. All rights reserved. Delivery subject to availability; right of technical modifications reserved. All hardware and software names used are trademarks of their respective manufacturers. This manual is printed on paper treated with chlorine-free bleach. Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.ivz 7. July 2009 Stand 12:46.31 © cognitas GmbH 2001-2007 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 Contents 1 Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.1 Structure of the POSIX documentation . . . . . . . . . . . . . . . . . . . . . . . 12 1.2 Target group . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3 Summary of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.4 Changes since the last version of the manual . . . . . . . . . . . . . . . . . . . 14 1.5 Notational conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2 Working with the POSIX shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2.1 Accessing the POSIX shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 2.2 Special features of POSIX shell operation 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 2.3.16 2.3.17 Entering commands from the POSIX shell . . Chaining commands . . . . . . . . . . . . . . . Further input after command invocation . . . . . Command options . . . . . . . . . . . . . . . . Specifying file names . . . . . . . . . . . . . . . Built-in POSIX commands . . . . . . . . . . . . I/O redirection . . . . . . . . . . . . . . . . . . Shell procedures and processes . . . . . . . . . Processing commands using the POSIX shell . . Compound commands . . . . . . . . . . . . . . Comments . . . . . . . . . . . . . . . . . . . . Aliasing . . . . . . . . . . . . . . . . . . . . . . Tilde substitution . . . . . . . . . . . . . . . . . Command substitution . . . . . . . . . . . . . . POSIX shell variables and parameter substitution Blank interpretation . . . . . . . . . . . . . . . . File name generation . . . . . . . . . . . . . . . Quoting metacharacters . . . . . . . . . . . . . U22794-J-Z125-6-76 12 . . . . . . . . . . . . . . . . . . . . . 27 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 32 33 34 35 36 36 39 40 41 45 45 46 47 48 53 54 55 Contents 2.3.18 2.3.19 2.3.20 2.3.21 2.3.22 2.3.23 2.3.24 2.3.25 Arithmetic evaluation . Conditional expressions Environment . . . . . . Functions . . . . . . . Jobs . . . . . . . . . . Signals . . . . . . . . Execution . . . . . . . Command re-entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 57 60 61 62 63 64 65 2.4 2.4.1 2.4.2 Command summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Summary of all commands of the POSIX shell . . . . . . . . . . . . . . . . . . . . . 66 Command summary according to functions . . . . . . . . . . . . . . . . . . . . . . 72 2.5 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3 International environment (NLS locale) 3.1 Native language support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 3.2 3.2.1 3.2.2 3.2.3 3.2.4 Defining an internationalized environment The personal internationalized environment . Precedence among environment variables . . Supplied locales . . . . . . . . . . . . . . . . Restrictions . . . . . . . . . . . . . . . . . . 4 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 adduser alias ar asa at awk basename batch bc bg bs2cmd bs2cp bs2do bs2file bs2lp bs2pkey add individual user number . . . . . . . . . . . . . . . . define or display aliases . . . . . . . . . . . . . . . . . . archive maintainer . . . . . . . . . . . . . . . . . . . . . interpret carriage-control characters . . . . . . . . . . . execute commands at a later time . . . . . . . . . . . . pattern scanning and processing language . . . . . . . . return non-directory portion of path name . . . . . . . . execute commands at a later time . . . . . . . . . . . . arbitrary-precision arithmetic language . . . . . . . . . . run jobs in the background . . . . . . . . . . . . . . . . execute BS2000 command (BS2000) . . . . . . . . . . . copy POSIX/BS2000 files (BS2000) . . . . . . . . . . . . calling BS2000 procedures from the POSIX shell (BS2000) set BS2000 file attributes (BS2000) . . . . . . . . . . . . send files to a printer (BS2000) . . . . . . . . . . . . . . set pkeys (BS2000) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 87 89 90 90 91 92 94 99 100 107 149 151 154 166 167 169 183 189 190 192 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. July 2009 Stand 12:46.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.ivz Contents cal cancel cat cd chgrp chmod chown cksum cmp comm command compress cp cpio crontab csplit cut date dd debug df diff dirname du dumpfs echo ed edt egrep env eval ex exec exit expand export expr false fc fg fgrep file find fold print calendar . . . . . . . . . . . . . . . . . . . . . . . . . cancel line printer requests . . . . . . . . . . . . . . . . . . concatenate and print files . . . . . . . . . . . . . . . . . . change working directory . . . . . . . . . . . . . . . . . . . change file group ownership . . . . . . . . . . . . . . . . . change file modes . . . . . . . . . . . . . . . . . . . . . . change file ownership . . . . . . . . . . . . . . . . . . . . write file checksums and sizes . . . . . . . . . . . . . . . . compare two files . . . . . . . . . . . . . . . . . . . . . . . select or reject lines common to two files . . . . . . . . . . execute a simple command . . . . . . . . . . . . . . . . . compress files . . . . . . . . . . . . . . . . . . . . . . . . copy files . . . . . . . . . . . . . . . . . . . . . . . . . . . copy in and out . . . . . . . . . . . . . . . . . . . . . . . . schedule periodic background work . . . . . . . . . . . . . split files based on context . . . . . . . . . . . . . . . . . . cut out selected fields of each line of a file . . . . . . . . . . write the date and time . . . . . . . . . . . . . . . . . . . . convert and copy a file . . . . . . . . . . . . . . . . . . . . program debugging in forked tasks . . . . . . . . . . . . . . report free disk space . . . . . . . . . . . . . . . . . . . . compare two files . . . . . . . . . . . . . . . . . . . . . . . return directory portion of pathname . . . . . . . . . . . . . estimate file space usage . . . . . . . . . . . . . . . . . . dump file system . . . . . . . . . . . . . . . . . . . . . . . write arguments to standard output . . . . . . . . . . . . . interactive line editor . . . . . . . . . . . . . . . . . . . . . screen-oriented editor EDT (BS2000) . . . . . . . . . . . . . search a file with an ERE pattern . . . . . . . . . . . . . . set environment for command execution . . . . . . . . . . . construct command by concatenating arguments . . . . . . command and display editor . . . . . . . . . . . . . . . . . execute commands and open, close or copy file descriptors cause the shell to exit . . . . . . . . . . . . . . . . . . . . convert tabs to spaces . . . . . . . . . . . . . . . . . . . . set export attribute for variables . . . . . . . . . . . . . . . evaluate arguments as an expression . . . . . . . . . . . . return false value . . . . . . . . . . . . . . . . . . . . . . . process command history list . . . . . . . . . . . . . . . . run jobs in the foreground . . . . . . . . . . . . . . . . . . search a file for a fixed-string pattern . . . . . . . . . . . . determine file type . . . . . . . . . . . . . . . . . . . . . . find files . . . . . . . . . . . . . . . . . . . . . . . . . . . . filter for folding lines . . . . . . . . . . . . . . . . . . . . . U22794-J-Z125-6-76 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 195 197 199 202 204 210 212 215 217 220 224 227 233 238 245 250 254 260 265 267 274 279 280 282 284 289 308 310 316 320 323 353 358 361 363 366 371 372 376 377 382 385 392 Contents fsck fsexpand ftyp gencat getconf getopts grep hash hd head iconv id info ipcrm ipcs jobs join kill let lex ln locale localedef logger logname lp lpstat ls mailx make man mesg mkdir mkfifo mkfs mknod more mount mountall mv newgrp nice nl nm file system check . . . . . . . . . . . . . . . . . . . . . expand existing file systems . . . . . . . . . . . . . . . define file processing mode (BS2000) . . . . . . . . . . . generate a formatted message catalog . . . . . . . . . . get configuration values . . . . . . . . . . . . . . . . . . parse utility options . . . . . . . . . . . . . . . . . . . . search a file for a pattern . . . . . . . . . . . . . . . . . remember or report utility locations . . . . . . . . . . . . hex dump . . . . . . . . . . . . . . . . . . . . . . . . . copy the first part of files . . . . . . . . . . . . . . . . . code set conversion . . . . . . . . . . . . . . . . . . . . return user identity . . . . . . . . . . . . . . . . . . . . online diagnostic tool . . . . . . . . . . . . . . . . . . . remove inter-process communication facilities . . . . . . inter-process communication status . . . . . . . . . . . display status of jobs in the current session . . . . . . . relational database operator . . . . . . . . . . . . . . . terminate or signal processes . . . . . . . . . . . . . . . integer arithmetic . . . . . . . . . . . . . . . . . . . . . generate programs for lexical tasks . . . . . . . . . . . . link files . . . . . . . . . . . . . . . . . . . . . . . . . . get locale-specific information . . . . . . . . . . . . . . define local environment . . . . . . . . . . . . . . . . . log messages . . . . . . . . . . . . . . . . . . . . . . . return user‘s login name . . . . . . . . . . . . . . . . . send files to a printer . . . . . . . . . . . . . . . . . . . report line printer status information . . . . . . . . . . . list directory contents . . . . . . . . . . . . . . . . . . . interactive message processing system (mail extended) . maintain, update and regenerate groups of programs . . display system documentation . . . . . . . . . . . . . . permit or deny messages . . . . . . . . . . . . . . . . . make directories . . . . . . . . . . . . . . . . . . . . . make FIFO special files . . . . . . . . . . . . . . . . . . make file system . . . . . . . . . . . . . . . . . . . . . make an inode . . . . . . . . . . . . . . . . . . . . . . display files on a page-by-page basis . . . . . . . . . . . mount a file system . . . . . . . . . . . . . . . . . . . . mount file systems . . . . . . . . . . . . . . . . . . . . move files . . . . . . . . . . . . . . . . . . . . . . . . . change to a new group . . . . . . . . . . . . . . . . . . invoke a utility with an altered system scheduling priority . line numbering filter . . . . . . . . . . . . . . . . . . . . write the name list of an object file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 397 399 401 404 408 411 416 420 423 425 427 430 432 434 439 440 444 448 450 453 462 466 470 471 472 477 480 488 526 535 537 539 541 543 544 546 551 562 564 568 571 572 579 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. July 2009 Stand 12:46.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.ivz Contents nohup invoke a utility immune to hangups . . . . . . . . . . . od dump files in various formats . . . . . . . . . . . . . . paste merge corresponding or subsequent lines of files . . . patch apply changes to files . . . . . . . . . . . . . . . . . pathchk check pathnames . . . . . . . . . . . . . . . . . . . . pax portable archive interchange . . . . . . . . . . . . . . pdbl set up and manage user-specific program cache . . . pkginfo show information on software packages in POSIX . . . posdbl set up and manage global program cache . . . . . . . pr prepare files for printing . . . . . . . . . . . . . . . . print write arguments to standard output . . . . . . . . . . printf formatted output . . . . . . . . . . . . . . . . . . . . ps report process status . . . . . . . . . . . . . . . . . . pwd return working directory name . . . . . . . . . . . . . rcp remote file copy . . . . . . . . . . . . . . . . . . . . read read a line from standard input . . . . . . . . . . . . . readonly set read-only attributes for variables . . . . . . . . . . renice set system scheduling priorities of running processes . rm remove directory entries . . . . . . . . . . . . . . . . rmdir remove directories . . . . . . . . . . . . . . . . . . . rmpart remove partition . . . . . . . . . . . . . . . . . . . . rsh remote shell . . . . . . . . . . . . . . . . . . . . . . sed stream editor . . . . . . . . . . . . . . . . . . . . . . set set or unset options and positional parameters . . . . sh shell, the standard command language interpreter . . shift shift positional parameters . . . . . . . . . . . . . . . show_pubset_export show file system affected by pubset export . . . . . . sleep suspend execution for an interval . . . . . . . . . . . sort sort, merge or sequence check text files . . . . . . . . split split a file into pieces . . . . . . . . . . . . . . . . . . start_bs2fsd start copy daemons . . . . . . . . . . . . . . . . . . strings find printable strings in files . . . . . . . . . . . . . . stty check and change terminal options (set terminal type) sum print checksum and block count of a file . . . . . . . . sync flush system buffers . . . . . . . . . . . . . . . . . . tabs set terminal tabs . . . . . . . . . . . . . . . . . . . . tail deliver the last part of a file . . . . . . . . . . . . . . . talk talk to another user . . . . . . . . . . . . . . . . . . . tar file archiver . . . . . . . . . . . . . . . . . . . . . . . tee join pipes and make copies of input . . . . . . . . . . test evaluate expression . . . . . . . . . . . . . . . . . . time time a simple command . . . . . . . . . . . . . . . . U22794-J-Z125-6-76 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 584 588 593 597 600 607 611 614 618 625 626 630 638 639 643 647 649 650 652 654 655 659 670 679 682 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684 686 688 695 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698 699 701 710 712 713 717 721 724 730 732 739 Contents times write process times . . . . . . . . . . . . . . . . . . touch change file access and modification times . . . . . . tput change terminal characteristics . . . . . . . . . . . . tr translate characters . . . . . . . . . . . . . . . . . . trap trap signals . . . . . . . . . . . . . . . . . . . . . . true return true value . . . . . . . . . . . . . . . . . . . . tsort topological sort . . . . . . . . . . . . . . . . . . . . tty output path name of current terminal . . . . . . . . . type write a description of command type . . . . . . . . . typeset set attributes for variables . . . . . . . . . . . . . . . ulimit set or report file size limit . . . . . . . . . . . . . . . umask get or set the file mode creation mask . . . . . . . . umount unmount a file system . . . . . . . . . . . . . . . . . umountall unmount file systems . . . . . . . . . . . . . . . . . unalias remove alias definitions . . . . . . . . . . . . . . . . uname return system name . . . . . . . . . . . . . . . . . . uncompress expand compressed files . . . . . . . . . . . . . . . unexpand convert spaces to tabs . . . . . . . . . . . . . . . . uniq report or filter out repeated lines in a file . . . . . . . unset unset values and attributes of variables and functions usp set POSIX control parameters dynamically . . . . . . uudecode decode a binary file . . . . . . . . . . . . . . . . . . uuencode encode a binary file . . . . . . . . . . . . . . . . . . uuname list names of known systems . . . . . . . . . . . . . vi screen oriented (visual) display editor . . . . . . . . wait await process completion . . . . . . . . . . . . . . . wc word, line and byte or character count . . . . . . . . whence query command type . . . . . . . . . . . . . . . . . who display who is on the system . . . . . . . . . . . . . write write to another user . . . . . . . . . . . . . . . . . xargs construct argument list(s) and execute command . . yacc yet another compiler-compiler . . . . . . . . . . . . . zcat expand and concatenate compressed data . . . . . . : return true value . . . . . . . . . . . . . . . . . . . . . execute commands in current environment . . . . . . [ËË] evaluate expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741 742 746 752 758 766 767 769 771 773 775 778 781 782 783 785 787 789 791 794 796 798 800 802 803 843 846 848 849 854 858 863 866 868 870 872 U22794-J-Z125-6-76 7. July 2009 Stand 12:46.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.ivz Contents 5 Tables and directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873 5.1 Summary of command XPG4 conformity . . . . . . . . . . . . . . . . . . . . . . 873 5.2 Regular POSIX shell expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 877 5.3 Metacharacters for the POSIX shell . . . . . . . . . . . . . . . . . . . . . . . . . 884 5.4 ASCII character set (ISO 646) 5.5 EDF04 character set . . . . . . . . . . . . . . . . . . . . . . . . . . . . 889 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893 Related publications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 895 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899 U22794-J-Z125-6-76 Contents U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k01 7. Juli 2009 Stand 11:58.24 1 Preface POSIX (portable open system interface for UNIX) is a range of UNIX-based standards which ensure the compatibility and interoperability of applications in a heterogeneous network. A heterogeneous network consists of computers from different manufacturers, as well as system and application software from different software suppliers. The POSIX standard was defined as the national American standard by the Institute of Electrical and Electronics Engineers (IEEE) in 1989. It was then extended by the X/OPEN consortium, and in 1990 became adopted as the international standard. (X/OPEN Portability Guide IV). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The X/OPEN Portability Guide IV, also known as XPG4 standard, comprises 7 volumes, including interface definitions for basic operating systems, programming languages, data management and networking. The BS2000/OSD operating system as of V2.0 supports the XPG4 standards which are contained in the first two volumes: ● Volume 1: System Interfaces and Headers (approx. 350 program interfaces) ● Volume 2: Commands and Utilities (approx. 200 user interfaces) In order to support these interfaces, the POSIX functionality was integrated into BS2000/OSD. POSIX designates both the IEEE standard and the BS2000/OSD “POSIX” functionality. POSIX satisfies the requirements to allow its certification according to the XPG4 standard, which is carried out in two stages: at the end of 1995, BS2000/OSD received the “XPG4 base branding” (XPG4) from “The Open Group” (previously X/OPEN), and around mid 1997 it received branding according to the “XPG4 UNIX profile” (also known as XPG4.2 or UNIX95). In addition, BS2000/OSD with its POSIX subsystem has been certified as an internet server by “The Open Group” in 1999. The kernel of the POSIX software product is implemented as a BS2000 subsystem. The library functions of the XPG4 standard are available to the user via a C library, and a defined set of commands is available via a shell (POSIX shell). The C library is a component of the product CRTE (Common RunTime Environment). Application programs can be easily ported with POSIX, irrespective of the operating system being used. Programs consistent with XPG4 can therefore also run in BS2000/OSD following recompilation. POSIX program interfaces are offered together with BS2000 program interfaces. It is possible to use a combination of both BS2000 and POSIX program interfaces in the same program, albeit with certain restrictions. U22794-J-Z125-6-76 11 Structure of the POSIX documentation Preface 1.1 Structure of the POSIX documentation The following documentation is available to help you to familiarize yourself with and work effectively in the POSIX subsystem in BS2000/OSD: ● The POSIX manual “Basics for Users and System Administrators” [1] provides an introduction into working with the POSIX subsystem. It also describes the administration tasks that will arise when dealing with POSIX, and gives information on which BS2000 software products you can use in conjunction with this subsystem. ● This manual, POSIX Commands, contains a description of the POSIX commands with which you can work in the POSIX shell. POSIX documentation in the BS2000/OSD environment The functionality of various software products in the BS2000/OSD environment is being expanded to enable you to combine these products with the use of the POSIX functions. A series of utilities provide access to the POSIX file system. As a result, you can, for example, use EDT to process files from the POSIX file system. Now that the CRTE (Common RunTime Environment) has been extended in accordance with the XPG4 standard, you can use the C Library Functions to write portable C programs irrespective of which operating system is running. The manual “Basics for Users and System Administrators” [1] is the basic requirement for accessing POSIX functions from within other software products. 1.2 Target group The POSIX commands represent a comprehensive set of versatile programs and procedures for process control. This manual contains a description of POSIX commands. It is a fundamental reference work for all POSIX users who already possess some basic knowledge of POSIX operation. The level of knowledge required corresponds to the information presented in the POSIX manual POSIX manual “Basics for Users and System Administrators” [1]. For further literature, please refer to the section References. 12 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.24 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k01 Preface Summary of contents 1.3 Summary of contents The chapter Working with the POSIX Shell provides basic information about POSIX shell operation. It also provides a function-specific command summary and an example of accessing and working in the POSIX shell. The chapter International Environment (NLS Locale) tells you something about the Native Language System. The chapter Commands presents the commands in alphabetical order. In order to help users locate the relevant information, the outer running title of each page specifies the name of the described command together with a supplementary keyword in the case of very long descriptions. The chapter Tables and directories provides a summary of the XPG4 conformity of the POSIX commands. It also includes lists of the metacharacters and regular expressions of the POSIX shell and tables of the ASCII and EBCDIC character sets. The index at the back of the book is intended to help you locate topics more quickly. For technical reasons the printed manual is devided into two volumes. README file Information on functional changes and additions to the current product version described in this manual can be found in the product-specific README file. You will find the README file on your BS2000 computer under the file name SYSRME.product.version.language. The user ID under which the README file is cataloged can be obtained from your systems support. You can view the README file using the /SHOW-FILE command or an editor, and print it out on a standard printer using the following command: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 /PRINT-DOCUMENT filename, LINE-SPACING=*BY-EBCDIC-CONTROL U22794-J-Z125-6-76 13 Changes since the last version of the manual Preface 1.4 Changes since the last version of the manual This edition of the present manual features the following changes compared to the previous version (March 2007): The following new commands were added to the Commands chapter: show_pubset_export show file systems affected by EXPORT-PUBSET start_bs2fsd start copy daemons The following changes were made to the descriptions of the commands below: 14 df Support of bs2fs file systems mount Support of bs2fs file systems mountall Support of bs2fs file systems pathchk Support of bs2fs file systems umount Support of bs2fs file systems umountall Support of bs2fs file systems U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.24 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k01 Preface Notational conventions 1.5 Notational conventions As far as is possible, each command description is in a uniform pattern: ● Outer running title ● Inner running title (optional) ● Main title ● Description ● Synopsis ● Syntax description ● Exit status (optional) ● Error messages (optional) ● Files (optional) ● Environment variables (optional) ● Locale (optional) ● Examples (optional) ● See also (optional) These elements are now described in detail. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Outer running title The outer running title gives the command name. In the case of the larger commands it also acts as an orientation guide, the command name being followed by a keyword indicating the topic dealt with on the page. Inner running title (optional) The inner running title classifies certain commands for the sake of clarity, e.g. Built-in sh command. Main title The main title includes: – the name of the command – a short description of the command – the suffix (BS2000) in the case of commands which are specially provided for operation with BS2000 as an extension to the XPG4 standard. U22794-J-Z125-6-76 15 Notational conventions Preface Description Here the following are described: – – – – – the functionality of the command the various purposes of individual formats if more than one is available the environment in which the command is to be used (e.g. entries in files, permissions, etc.) background information points to be observed before and after the command call. In the case of commands which call complex programs (e.g. awk, sh), this section simply describes the program call. For further information, e.g. about awk operation, please refer to the associated syntax section. Syntax cmd[Ë-a][Ë-b][Ë-c][Ë-darg1][Ë-fËarg2]ËfileË... Syntax The meaning of the metasyntax is described below. In the syntax: Boldface characters Constants: These characters must be entered exactly as shown. Normal characters Variables: These characters stand for other characters for which you may select and enter a suitable value. 16 [] Optional: arguments within square brackets are optional and may be omitted. The effects of these arguments are explained in the description of the options and arguments. You must not enter the square brackets themselves, unless specifically instructed to do so. | A vertical bar identifies alternatives from which you may choose one only. Ë Indicates a mandatory blank (space). ... Ellipses indicate that the preceding argument can be repeated. If blanks that are not part of the argument have to be placed between repetitions, the ellipses are preceded by Ë (space). U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.24 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k01 Preface Notational conventions Example cmd[Ë-a][Ë-b][Ë-c][Ë-darg1][Ë-fËarg2]ËfileË... The following arguments are mandatory: – cmd – one or more files, each preceded by a blank. The following arguments are optional extras: – one or more of options -a, -b, -c; these options can either be listed separately: -a -b -c or grouped together: -abc – option -d, where arg1 must be replaced with an argument – option -f, where arg2 must be replaced with an argument. In descriptive text: No distinction is made between constants and variables in the descriptive text; all syntax elements as well as miscellaneous file names, path names, and commands are given in italics. Input Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 In application examples, input into the system is identified by fixed-width, semibold type. Since all input lines are terminated with the Ú key at character-mode terminals, and with the keys [EM][DUE] at block-mode terminals, the keys at the ends of input lines are not specified. Many inputs are terminal-dependent, they are different for block and character-mode terminals (see also “Terminal support” on page 27): Output Operating system output is shown in fixed-width font, except in descriptive text, where it is shown in italics. U22794-J-Z125-6-76 17 Notational conventions Preface Syntax description option (For a description of options see the section “Command options” on page 34) argument Description of the remaining arguments which you can pass when calling a command, e.g. input files, output files, parameters, variables, field separators etc. Exit status (optional) The exit status is the value which a command returns to the calling process following execution. The exit status provides information about command execution. The exit status is a numerical value which is contained in the ? variable. You can enter the command echo $? to query the exit status. The exit status section is only included if the exit status deviates from following basic rule: 0 successful execution of the command >0 the command has failed Error messages (optional) Important error messages are listed and explained here. Additional notes indicate how errors can be avoided and recovered. Unless otherwise specified, error messages are sent to the standard error output. Standard error (stderr) is usually the screen. Files (optional) This section lists files that the command accesses or creates. Environment variables (optional) Some commands inspect the values of environment variables. These are listed here. Locale (optional) This section describes how NLS affects the command (see the chapter “International environment (NLS locale)” on page 85). 18 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k01 Preface Notational conventions Examples (optional) 7. Juli 2009 Stand 11:58.24 Examples aim to illustrate: – the main function of the command – the use of the principal options – acceptable complex combinations of options and arguments See also (optional) This section contains references to other commands that perform similar functions or work in conjunction with the described command. References to literature containing more information on the command is provided where appropriate. System calls and library functions for C developers are indicated by a pair of parentheses, e.g. chdir(). Notes and warnings BS2000 Sections which refer to special characteristics of POSIX operation with the BS2000 are identified in this way. i This symbol indicates important information which you must be careful to observe. ! This symbol precedes warnings which you should observe in the interests of system and operating security. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 References The following examples show how references to other sections of the text, manuals, commands, functions, system calls and file formats are presented. see the section “Command summary” on page 66 Reference to the section “Function-specific command summary” in this manual see “Basics for Users and System Administrators” [1] Reference to a manual which is listed as number [1] under Related publications at the back of this manual see also awk Reference to the awk command in this manual see also chdir() [4] Reference to the C function, system call or file format chdir() in the manual which is listed as number [4] under Related publications at the back of this manual U22794-J-Z125-6-76 19 Notational conventions 20 Preface U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 7. Juli 2009 Stand 11:58.25 2 Working with the POSIX shell The POSIX shell is the interface which connects you to the POSIX subsystem via the C runtime system/libraries. The figure 1 illustrates the structure of POSIX in BS2000 and the integration of the POSIX shell. POSIX applications BS2000 tools: C/C++ compiler SPOOL Binder loader EDT ... POSIX shell (commands) Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 C runtime system/libraries POSIX subsystem Interfaces to BS2000 basic functions Ported SINIX system kernel BS2000 interfaces/services BS2000/OSD-BC and other subsystems Figure 1: Structure of POSIX in BS2000 and integration of the POSIX shell The POSIX shell is a command interface which you can use in addition to the BS2000 command interface (see figure 2). U22794-J-Z125-6-76 21 Working with the POSIX shell When you have successfully accessed the POSIX shell, you may use all the commands of the POSIX shell. After leaving the POSIX shell you may again enter BS2000 commands. BS2000 application programs: EDT, HSMS, SPOOL ... Administrator interface POSIX shell and commands Programming environment: CRTE Library functions C/C++ compiler ... BLS ... Network management: SOCKETS, NFS ... Figure 2: The POSIX shell command level The POSIX shell reads commands from a terminal or from a file in the POSIX file system, interprets them in accordance with certain rules and is responsible for their execution. A file which contains commands for the POSIX shell is called a shell procedure (shell script). The operation and performance of the POSIX shell depend on whether the terminal at which the user is working is a block or character-mode terminal. The POSIX shell provides you with a comprehensive command language which you can use like a programming language. You can use the available commands to create your own programs which you can then run without the need for prior compilation. 22 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Accessing the POSIX shell 2.1 Accessing the POSIX shell You can access the POSIX shell in the following ways: ● via a BS2000 terminal (block-mode terminal) ● from a UNIX system (character-mode terminal) ● by means of an emulation BS2000/OSD POSIX File SYSSRPM Authentication Authentication /START-POSIX-SHELL Terminal emulation Terminal emulation Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 /LOGON BS2000 terminal (block terminal) Workstation / PC rlogin telnet Terminal on UNIX systems (character terminal) Figure 3: Ways of accessing the POSIX shell U22794-J-Z125-6-76 23 Accessing the POSIX shell Working with the POSIX shell Access via a BS2000 terminal After successfully logging on to BS2000, any BS2000 user can enter the /START-POSIXSHELL command to call the POSIX shell: START-POSIX-SHELL VERSION = *STD /,MONJV = *NONE / ,CPU-LIMIT = *JOB-REST / VERSION = *STD / Version number of the program to be called (in this case the POSIX shell). The default setting is *STD, which means that the version currently available is called. MONJV = *NONE / Name of the job variable which is to monitor the program. If this job variable does not yet exist, a new one is created. During the program run, the system sets the job variable to the appropriate values: $R Program running $T Program terminated $A Program terminated abnormally This operand is only available if the “Job Variables” software product is implemented (see also the “Job Variables” manual). CPU-LIMIT = *JOB-REST / Maximum CPU time (in seconds) that the program can take to run. If no time limit was set when the job was started (CPU-LIMIT=*NO), then the program ignores this specification and does not observe a time limit when running. If the program overruns the specified time, the program is interrupted during the dialog session and a corresponding message is output. Users can then either request a dump or abort or resume the program. If a STXIT routine has been defined in the program for the event that the CPU limit is reached, this routine runs and the program is terminated. In batch mode, the program is terminated if the time limit is exceeded. CPU-LIMIT = *JOB-REST If the job was started with a time limit, the value defined during system generation is used for the program. If not, the program runs with no time limit. 24 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Accessing the POSIX shell Return codes (SC2) 255 SC1 0 1 Main code CMD0001 CCM0999 Meaning/Guaranteed messages No errors The POSIX shell could not be started. Effect of the START-POSIX-SHELL command This command sets up the POSIX environment and calls the program entered in the SYSSRPM file for the relevant user. If you have entered the POSIX shell as a standard program in your user data, then after entering /START-POSIX-SHELL you can work interactively with the POSIX shell and you may use all the commands and functions of the POSIX shell. POSIX shell-specific commands are available for interaction between BS2000 and the POSIX subsystem. Terminating the POSIX shell In order to return to BS2000 you must first enter the exit command to close the POSIX shell. Access from a character terminal You can use the rlogin command to log on to a BS2000 host from a terminal of a UNIX system, provided you have the required authorization to access it. In other words, you will need to have a user ID (login name) that is authorized for POSIX rlogin access, the associated password, and an account number that can also be used for rlogin access accounting on the BS2000 host. After logging on, you can use POSIX as if in local mode. In order to connect to BS2000, you must enter the following command in the POSIX shell: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 rlogin [-l ] If you do not enter a login name then the login name under which you are logged on at the remote computer is used. If you use the rlogin command, the system asks for the password for the required login name. The password is verified by the BS2000 SRPM component (System Resources and Privileges Management): The BS2000 login name and password specifications are checked against the access control attributes of the home pubset. If they match then the user is granted access to the POSIX subsystem. If the SECOS product is employed then the access control procedure can be further refined by means of LOGON protection. If you use rlogin to access POSIX then you cannot use BS2000 commands. U22794-J-Z125-6-76 25 Accessing the POSIX shell Working with the POSIX shell Access via telnet The telnet daemon telnetd provides direct access to BS2000 via the telnet protocol from the UNIX system and also directly from the PC via the telnet application, which appears to POSIX as a character terminal and behaves as such. Access control is handled in the same way as for rlogin, i.e. via BS2000 access mechanisms. Access without the entry of a password, as realized between UNIX systems (i.e. via an entry in the .rhosts file), is not supported. Access via an emulation The third way of accessing POSIX is by means of a terminal emulation. This means that you must first log on to a workstation or PC and then start a terminal emulation to emulate either a terinal of a UNIX system or a BS2000 terminal. BS2000 terminal emulation When you access POSIX via a BS2000 terminal emulation such as the EM9750 or MT9750, for example, your terminal acts as a block-type terminal, which means that you can enter BS2000 commands and /START-POSIX-SHELL as if at a BS2000 terminal (see page 24). UNIX/SINIX terminal emulation for UNIX systems UNIX/SINIX terminal emulations are available for workstations with UNIX system with graphical OSF/Motif-based interfaces and also for PCs running Windows (e.g. EM97801 and SINIX-TE). These emulations act as a character terminal of a UNIX system and enable you to enter commands such as rlogin (see page 25). 26 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Special features of POSIX shell operation 2.2 Special features of POSIX shell operation Presettings in the user environment When you have successfully accessed the POSIX subsystem, the POSIX shell is started. Before the POSIX shell reports that it is ready for operation, the following presettings are made in the user environment: ● The POSIX shell initializes the standard shell variables. It allocates default values to the following variables: HOME, LANG, LOGNAME, MAIL, PATH, SHELL, TTY, TERM, TZ and USER. If a variable has already been predefined by the SDF-P variable SYSPOSIX then this value is adopted. However, the shell variables USER, TERM, TYP, LOGNAME, HZ, HOME and MAIL may not be set by the user. ● The file /etc/profile is executed. ● If you have created it, the file $HOME/.profile is executed. Terminal support POSIX supports the block-mode terminals which are used in BS2000 as well as the character-mode terminals employed in UNIX systems. The latter are connected to UNIX multiuser systems and are operated by POSIX via networks. If you access POSIX via a workstation then a character-mode terminal is emulated. In the case of SINIX workstations, this can, for example, be a type 97801 terminal. Block-mode and character-mode terminals operate differently: In the case of character-mode terminals each character that is input is immediately transferred to the UNIX system where it is transferred to the screen as a response to the input and displayed. Control functions such as cursor movement, uppercase/lowercase notation or the buffering of transfers are performed by the computer to which the terminal is connected. Screen-oriented applications are only permitted at character-mode terminals. ● In contrast, block-mode terminals transfer all the text entered at the screen to the computer in the form of a data block. Control functions are performed at the unit itself. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 ● Block-mode terminals are directly connected to the BS2000 and POSIX. Both BS2000 and POSIX commands can be entered at this terminal type. For BS2000 security reasons it is only allowed to write via block-mode terminals to terminals of the own process group. E.g. a cp /dev/term/xxx processed for a blockmode terminal of another LOGON-Task will be rejected with permission denied. U22794-J-Z125-6-76 27 Special features of POSIX shell operation Working with the POSIX shell Many inputs are terminal-dependent, i.e. they are different for block and character-mode terminals: Block-mode terminal Character-mode terminal @@d [END] @@c [DEL] @@/ [CTRL][\] [EM][DUE] Ú - [CTRL][S] / [CTRL][Q] / [CTRL][Z]... Special functions (P keys, Ctrl keys) You can call the command bs2pkey to make the following settings for the [P3] and [P4] keys: [P3] with @@c ([CTRL][C]) [P4] with @@d ([CTRL][D]) You may either call the program in the POSIX shell (without options) or enter it in the file /etc/profile. In the latter case the program is called each time the shell is activated. File transfer POSIX files contain no records. Instead, they are byte-oriented. In contrast, BS2000 files contain record-oriented and/or PAM block-oriented data. By default, POSIX handles files in EBCDIC format, whereas UNIX systems, MS-DOS and Windows handle files in ASCII format. ASCII files stored in the POSIX file system can only be processed in the POSIX shell if they have first been converted. Routines for the conversion of data between POSIX and BS2000 formats are available in order to permit the exchange of POSIX and BS2000 files. Files are converted from the EBCDIC DF 03 character set to ASCII ISO 7-bit code, and vice versa (see also chapter “Tables and directories” on page 873). Only pure text files can be converted. 28 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Special features of POSIX shell operation Automatic conversion The environment variable IO_CONVERSION determines whether files accessed with POSIX commands (e.g. awk, cat, grep...) on mounted ASCII file systems are converted automatically. IO_CONVERSION is set to the value "NO" by default, which means that no automatic conversion occurs. If desired, automatic conversion can be enabled with the following command: export IO_CONVERSION=YES If you want to set automatic conversion for a POSIX user as the default value directly on starting the POSIX shell, this export command must be entered in the .profile file in the HOME directory of that user. i Note that automatic conversion must not be enabled when using the following tools, since the tools themselves also perform the same conversion: dd, iconv, edt with the -k option, and bs2cp with the -k option. Handling of archives/libraries: ar does not convert automatically, since ar libraries often contain binary data. pax and tar convert automatically. However, a pax or tar archive must not be copied with cp if automatic conversion is enabled. BS2000 Record-oriented Coding: EBCDIC Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 File structure: POSIX Byte-oriented EBCDIC/ASCII POSIX/BS2000 files a) Files imported from other UNIX systems bs2cp, edt b) iconv c) ASCII EBCDIC Figure 4: File transfer U22794-J-Z125-6-76 29 Special features of POSIX shell operation Working with the POSIX shell a) Transferring files from POSIX to BS2000 (as seen by the POSIX shell): You use the POSIX command bs2cp or edt to transfer files from POSIX to BS2000. You do not need to specify the -k option if the files use the EBCDIC character set in the two file systems. In addition, you may define file attributes for the BS2000 file. To do this you must use the POSIX command bs2file to define the BS2000 file attributes before issuing the "copy" command bs2cp. bs2file is mapped to the BS2000 command SET-FILEATTRIBUTES. b) Transferring files from BS2000 to POSIX (as seen by the POSIX shell): You use the POSIX command bs2cp or edt to transfer files from BS2000 to POSIX. You do not need to specify the -k option if the files use the EBCDIC character set in the two file systems. Depending on the BS2000 file type (SAM, ISAM or PAM) the following applies: – PAM files are always stored as binary files. – ISAM files are generally stored as text files in the POSIX file system. – In the case of SAM files and LMS elements (type S, J, X ,D), you can choose whether the file/element should be placed in the POSIX file system as a text file, binary file or binary text file. To do this, you must use the POSIX command ftype to specify the file processing mode before issuing the "copy" command bs2cp. c) Use the POSIX command iconv to perform file conversion within the POSIX file system. The file contents are converted. 30 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Entering commands from the POSIX shell 2.3 Entering commands from the POSIX shell When you have successfully accessed the POSIX subsystem, the POSIX shell is started. If you are using the POSIX shell in interactive mode, the POSIX shell outputs the value of the environment variable PS1 as a prompt before reading a command. By default, this is the dollar sign ($), or (#) for the privileged user, followed by a blank (Ë). Commands are entered in the following format: command[Ëoptions][Ëparameters]Ë ...Ú For command you must specify the name of the POSIX command or shell procedure which is to be executed. The options allow you to specify control instructions for command execution. Under parameters you can enter a call argument which the POSIX shell passes to the command. You may also enter multiple call arguments for certain commands. At character-mode terminals you must use tabs or spaces to separate the command names and call arguments. After the final call argument you can conclude command input by pressing the Ú key (at character-mode terminals) or [EM][DUE] (at block-mode terminals). Pure BS2000 programs cannot be started from within the POSIX shell. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If the screen line is too short for the required input you may proceed in one of two ways: ● At the end of the line you may simply continue to type without pressing the Ú key. When you have entered the complete command, press the Ú key to terminate input. ● Enter {\}Ú to continue the line. The backslash (\) prevents the Ú key from terminating command input. You may then continue to enter the command. When you press Ú (without {\}), the command is executed. Every POSIX command returns a value to the POSIX shell in which it was called. This is its exit status. If the command was executed correctly this value is 0; if errors were encountered its value is not equal to 0. If a command outputs information on screen and the output exceeds the capacity of a screen page, then at character-mode terminals you can pause the output by pressing the key combination [CTRL][s] and continue it by pressing [CTRL][q]. This function is not supported at block-mode terminals. U22794-J-Z125-6-76 31 Chaining commands Entering commands from the POSIX shell 2.3.1 Chaining commands You can chain a set of commands together: ● You can use the | character to combine two commands to form a pipeline. ● You can use the characters; or & or && or || to combine multiple commands or pipelines to form a command list. Pipeline A pipeline is a sequence of two or more commands each of which is linked to the preceding command by means of the | character. A pipeline between two commands redirects the standard output of the first command to the standard input of the second command (see the section “I/O redirection” on page 36). For this reason, commands which are chained in this way must fulfil the following conditions: ● The first command must write to the standard output. ● The next command in the pipeline must read from the standard input. ● If the pipeline contains more than two commands, then all the commands which come between the first and last command of the pipeline must read from the standard input and write to the standard output. The POSIX shell starts all of the piped commands as independent parallel processes. However, in a monoprocessor system, the processor can only handle one of these processes during each time slice. For this reason, processor time is devoted to the individual processes in turn. Only the process corresponding to the first command in the pipeline does not receive its input from another process. Only the process corresponding to the last command in the pipeline does not route its output to another process. The POSIX shell waits until the last of the piped commands terminates before processing any further inputs. Command list A command list is a sequence of one or more pipelines separated by the symbols ; & && || and optionally terminated by ; & |& 32 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Further input after command invocation The symbols, ;, &, and |& have equal precedence, which is lower than that of && and ||. The symbols && and || also have equal precedence. A semicolon (;) causes sequential execution of the preceding pipeline; an ampersand (&) causes asynchronous execution of the preceding pipeline (i.e. the shell does not wait for that pipeline to finish). The symbol |& after a command list causes asynchronous execution of the preceding command or pipeline with a two-way pipe established to the parent shell. In the following, the term command refers to a command or a pipeline. The effect of the various characters is specified in the table below: Character Effect ; The POSIX shell does not process the next command until the preceding command has terminated. It does not, however, issue a prompt. & The POSIX shell starts the preceding command in the background and then immediately processes the following command. The POSIX shell redirects the standard input of all background commands to a file which has the properties of /dev/null. However, you may redirect the standard input of a background command to another file. && The POSIX shell does not execute the following command unless the preceding command returns the value 0 as its exit status. || The POSIX shell does not execute the following command unless the preceding command returns a value other than 0 as its exit status. |& The POSIX shell starts the preceding command in the background with a two-way pipeline to the parent shell. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 2.3.2 Further input after command invocation Some commands expect you to enter additional data from the keyboard after you have pressed Ú In such cases the cursor is positioned at the start of the next line and either no prompt appears at all or a special prompt, varying according to the command, appears instead. Each of the lines you now enter must be terminated with Ú. To terminate data entry, you generally either press [END] (or use @@d at block-mode terminals) or enter one of the special statements associated with your command. If you terminate a command with Ú leaving the command line incomplete, or if you escape Ú with a backslash (\), the POSIX shell outputs the value of the shell variable PS2 (by default the "greater than" character > and a blank Ë) as prompt. U22794-J-Z125-6-76 33 Command options Entering commands from the POSIX shell 2.3.3 Command options You can invoke commands with one or more options or with none at all. Options modify the way in which a command functions. They generally consist of a single letter. In the command syntax they are either shown exactly as you have to enter them (in bold type) or are collectively identified as "option" (in normal type). The following rules generally apply when you enter more than one option: ● The order in which you list the options is immaterial. ● Options without arguments can be entered in two ways: ● – singly, e.g.: cmdË-aË-bË-c – grouped, e.g.: cmdË-abc Options that require an argument, for example -dargument or -fË argument, cannot be combined with those that do not. Such options must be entered individually, with blanks (Ë) to separate them: cmdË-abcË-dargumentË-fËargument ● Options and option combinations are introduced by a minus sign (-): -abc. ● Two hyphens (--) may be used to indicate the end of the options. You need to use -- if the first argument begins with -. Most commands output a usage message if they are called with an incorrect option. The usage message tells you which options and operands can be used in conjunction with a command call. Example Output of a usage message when an incorrect option is specified $ lsË-y ls: Illegal option -- y ls: Usage: ls -1RadCxmnlogrtucpFbqisfLe [files] 34 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Specifying file names 2.3.4 Specifying file names The following conventions apply to file names: ● You may use any character with the exception of / and \0 (zero bytes terminating a character string). ● You should not enter the characters plus (+), minus (-) or period (.) at the beginning of a file name. The period is reserved for special files, e.g. for the file .profile. Example of the use of a file name beginning with the minus sign (-): touch -- -file1 (before the file name is entered, the (void) options must be terminated) ● For more information on the use of the characters *, ?, [...], see the section “File name generation” on page 54. ● You should not use a number of special characters (see the chapter “Tables and directories” on page 873). ● If the filename contains spaces or tabs you must place it inside quotes. ● Unlike BS2000, POSIX distinguishes between uppercase and lowercase in file names. ● You can specify a relative path name. Relative path names always start from the current directory. ● You can specify an absolute path name. Absolute path names start with a slash (/) and specify the name relative to the root directory. ● A file name must not exceed 1024 characters in length. This limit includes the directory names, the name of the file itself and the slashes which are used as separators. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 There are two ways of specifying the names of files and directories in the POSIX shell: U22794-J-Z125-6-76 35 Built-in POSIX commands Entering commands from the POSIX shell 2.3.5 Built-in POSIX commands Built-in POSIX commands are commands which the POSIX shell interprets and processes itself without, consequently, generating a new process. They differ from all the other “external” commands in the following ways: ● As subprograms, they are components of the binary file /bin/sh. This means that you are not able to rename them. You can change access permissions for the /bin/sh file only, not for the individual builtin POSIX commands. ● The POSIX shell prioritizes execution of built-in POSIX commands. If a built-in POSIX command has the same name as an external command then the POSIX shell always executes the built-in POSIX command when this name is specified. The external command is executed if the call name contains a slash (/), for example if it is called with the corresponding absolute path name. ● Built-in POSIX commands are faster because they are executed by the POSIX shell itself. 2.3.6 I/O redirection Before a command is executed, its input and output may be redirected by means of a special notation interpreted by the POSIX shell. The following arguments may appear anywhere in a simple command or may precede or follow a command. They are not passed on to the invoked command, but are interpreted by the shell. Command and parameter substitution occurs before the specified file or file descriptor is used. File name generation is performed only if the pattern matches a single file. Blank interpretation is not performed file Redirects the standard output (file descriptor 1) of a command to file, so that output from the command is written to file. If the file does not exist, it is created. If it does exist, is a regular file, and the noclobber option is set (see Built-in commands, set -o), this causes an error. If noclobber is not set, the file is truncated to zero length and its existing contents are lost. >|file Same as >file, except that it overrides the noclobber option. 36 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell I/O redirection >>file Redirects the standard output (file descriptor 1) of a command to file, so that output from the command is written to file. If the file exists, output is appended to it; otherwise, the file is created. <>file Opens file for reading and writing as standard input. <<[-]string Introduces a "here document" (explained below). "Here documents" are used primarily in shell procedures to supply values to commands which can read from standard input. No parameter substitution, command substitution or file name generation is performed on string. Input to the POSIX shell is read up to (but excluding) a line that literally matches string or to an end-of-file. The resulting document, called a "here document", becomes the standard input for the command. If one of the characters in string is quoted then all the characters of the "here document" are quoted for the POSIX shell. i The string marking the last line must not be quoted. If no characters of string are quoted: – parameter and command substitution is performed, – escaped newlines (\newline) are ignored, and – a backslash (\) must be used to quote backslashes (\), dollar signs ($), backquotes (`) and the first character of string if they are to be treated literally in the text. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If - is appended to <<, then all leading tabs are stripped from string and from each line in the here document. <&digit >&digit In the first form, the standard input is duplicated from file descriptor digit, i.e. is read from the file associated with digit. The second form does the same for the standard output. <&>&The first form closes the standard input for the command, so that EOF is the only input to the command. The second form closes the standard output for the command, so that the command does not write any output. <&p >&p The input from the co-process in a two-way pipeline is redirected to standard input. Similarly, the output to the co-process is redirected to standard output. U22794-J-Z125-6-76 37 I/O redirection Entering commands from the POSIX shell If one of the above redirections is preceded by a digit, the file descriptor number referred to is that specified by the digit (instead of the default 0 for stdin and 1 for stdout). Example To open file descriptor 2 (stderr) for writing as a duplicate of file descriptor 1 (stdout): ... 2>&1 Order of redirections and background commands The order in which redirections are specified is significant. The POSIX shell evaluates each redirection in terms of the association (file descriptor, file) at the time of evaluation. For example: ... 1>file 2>&1 first associates standard output (file descriptor 1) with file and then associates standard error (file descriptor 2) with the file associated with file descriptor 1 (i.e. file). In other words, both the standard output and the error messages from the command are written to file. If the order were reversed, file descriptor 2 would be associated with the terminal (assuming file descriptor 1 had been), file descriptor 1 with file. This would mean that only the standard output would be written to file, not the error messages. If you use & to start a command in the background without active job control then the standard input is automatically associated with a file which possesses the same properties as /dev/null. If job control is active then the environment for command execution contains the same file descriptors, modified as appropriate by the input/output statements, as the executing POSIX shell. You can set commands or pipelines to run in the background from within a script. They can then communicate with your program. To spawn a co-process of this type, you put the operator |& after the command. You can only use two-way pipes in scripts, not on the command line. Command strings can be called as two-way pipes. If you abort the original process (e.g. with kill -9 PID) and then later attempt to write another command to a two-way pipe then a subshell is indeed called but the process is stopped. You receive the error message: sh: bad file unit number. 38 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Shell procedures and processes 2.3.7 Shell procedures and processes Shell procedures are commands which have been grouped together to form a program. In order to create a shell procedure you must write the desired sequence of commands to a file. Enter sh to call a shell procedure. If the file possesses execution permission (chmod +x ), you can call this command sequence directly, that is to say without sh. This section describes the effect of the POSIX process structure when you are working with the POSIX shell, i.e. when you are entering commands or working with shell procedures. Any input that you enter after /START-POSIX-SHELL is received by the POSIX shell and processed accordingly. The most important commands are implemented as “built-in” commands. Some commands actually spawn a separate process, so the process in which the POSIX shell is running thus becomes a parent process. Basically, any process can spawn a new process. Until the process spawns another process it is the child process of a parent process. However, as soon as it generates a new process it becomes the parent process of the new child process. It nevertheless retains its status as the child process of the process to which it is subordinate. In other words, a process can simultaneously be a parent process and a child process. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The parent-child process hierarchy is of great importance if you want to pass environment variables in shell procedures. All users can define the environment variables with which they wish their POSIX shell (= parent process) to operate. However, these environment variables are initially known only by the POSIX shell. If a child process is to operate with the environment variables used in the parent process (= POSIX shell) then these variables must be exported to the child process. The export command is available for this purpose. U22794-J-Z125-6-76 39 Processing commands via the POSIX shell Entering commands from the POSIX shell 2.3.8 Processing commands using the POSIX shell Apart from the built-in POSIX commands, every command is linked to a file in the POSIX file system. The names of most command files are entered in the directory /usr/bin. The shell variable $PATH contains a list of directories in which commands are searched. When executing a command, the POSIX shell reads the command, searches in the directories contained in $PATH for a file name which is identical to the command name, and executes the command. In order to execute a command that is not one of its built-in commands, the POSIX shell spawns a new process and waits until that process terminates. It then displays the setting of the shell variable PS1 as a prompt (by default, this is $ for non-privileged users or # for privileged users), which indicates that it is ready to process a new command. If you enter the command date, for example, the current date will immediately be displayed, and the POSIX shell will then issue the prompt so that you can enter a new command. In the case of a command such as date, the period that elapses between command input and the POSIX shell reporting ready to process a new command is very short. However, this period may be substantially longer when a different command is input, for example when a file is compiled. This is because the POSIX shell does not report until execution of the command has been terminated. In order to avoid having to wait for extended periods at the terminal you can use the special character &. If you terminate command input with this character, the POSIX shell reports immediately with the screen prompt without waiting to terminate execution of the entered command. Commands which are terminated with & are started as background processes which you may leave to run without intervention. 40 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Compound commands 2.3.9 Compound commands Syntax forËidentifierË[ËinËword...];doËcommand_list;done or Syntax forËidentifierË[ËinËword_list] doËcommand_list done The for command can be used to repeatedly execute command_list. Each time a for loop is executed, identifier is set to the next word taken from the word_list. If word_list is omitted, the command_list is executed once for each positional parameter ("$@") that is set. Execution ends when there are no more words in the word_list. Syntax selectËidentifierË[ËinËword_list] doËcommand_list; done or Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Syntax selectËidentifierË[ËinËword_list] doËcommand_list done The select command can be used to repeatedly execute a given command_list under input control. select prints the set of words in word_list on standard output, each preceded by a number. The PS3 prompt is then printed, and a line is read from the standard input. The content of the line read from standard input is saved in the variable REPLY. If this line matches the number of one of the listed words, then the value of the parameter identifier is set to the word corresponding to this number. If the line is empty, the word_list is printed again, and identifier is set to the name of the shell script. If in word_list is omitted, then the positional parameters are used instead (as is done with for loops). The select loop is executed repeatedly until a break built-in or end-of-file is encountered. Example The following POSIX shell script can be used to selectively print information on each individual file in the current directory: select file in `ls` do if [ -z "$file" ] then echo "Select number" else ls -lsid $file fi done U22794-J-Z125-6-76 41 Compound commands Syntax Entering commands from the POSIX shell caseËwordËin [[(]pattern[pattern]...)commando_list;;]... esac The case command provides for conditional branching to a command list on the basis of a pattern. case executes the command_list associated with the first pattern that matches word. The form of the patterns is the same as that used for file name generation (see the section “File name generation” on page 54). i Syntax The optional left parenthesis preceding pattern must be specified if case commands are used within command substitutions with $(...). This produces paired parentheses constructs in $(...). ifËcommand_list1 thenËcommand_list2 [elifËcommand_list3 thenËcommand_list4]... [elseËcommand_list5] fi The if command can be used to conditionally execute a number of different command lists. The first list following if (command_list1) is executed as the condition, and if it returns a zero exit status (true), the list following the first then is executed (command_list2). Otherwise, the list following elif (command_list3) is executed as the next condition, and if its value is zero, the list following the next then (command_list4) is executed. Failing that, the else list (command_list5) is executed. If no else list or then list is executed, the if command returns a zero exit status. Syntax whileËcommand_list1 doËcommand_list2 done untilËcommand_list1 doËcommand_list2 done The while and until commands define loops with exit conditions. A while command repeatedly executes the condition command_list1, and if the exit status of the last command in the list is zero (i.e. true), it executes the do list in the body of the loop (command_list2); otherwise the loop terminates. If no commands in command_list2 (the do list) are executed, the while command returns a zero exit status. 42 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Compound commands until may be used in place of while to negate the loop termination test. The until command tests whether the exit condition is false (non-zero) and terminates the loop as soon as it returns an exit status of zero (true). Syntax continueËnumber continue continues with the next iteration of the superordinate for, while, until or select loop. If number has been specified, then the next iteration is performed in the superordinate loop which corresponds to number. If number is equal to 0, processing continues beyond the outermost loop. continue 1 has the same effect as continue. Syntax breakËnumber break aborts the superordinate for, while, until or select loop. If number has been specified, then execution continues in the superordinate loop which corresponds to number. If number is equal to 0, then the outermost loop is exited. break 1 has the same effect as break. Syntax returnËnumber If return is called in a function then the command returns to the calling procedure. The return status is determined by number or by the last command executed. If return is called outside of a function or in a procedure executed with a leading dot, then it has the same effect as a call to exit. Syntax (command_list) Executes command_list in a separate environment. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 i Syntax If two consecutive left-hand parentheses ( are required to define nested commands then these must be separated by a space. Failure to do so may result in their being interpreted as an arithmetical expression (see Command substitution). {Ëcommand_list;} command_list is simply executed in the current POSIX shell. i U22794-J-Z125-6-76 The left brace ’{’ must be followed by a space! Note that unlike the parentheses ( and ), the braces { and } are reserved words and must be typed at the beginning of a line or after a semicolon (;) in order to be recognized as such. 43 Compound commands Syntax Entering commands from the POSIX shell [[ËexpressionË]] Evaluates the conditional expression and returns a zero exit status if expression is true; otherwise, 1. See Conditional expressions for a description of expression. Syntax functionËidentifierË{Ëcommand_list;} identifierË()Ë{Ëcommand_list;} Defines a function named identifier. This name is used to call the function like a command. The body of the function consists of the command_list that is enclosed within curly braces { and }. The left brace ’{’ must be followed by a space! i The braces {} are unnecessary if – the command list consists of a single for, case, if, while, until or select statement. Example functionËidentifierËcaseËwordËinË... identifierË()ËforËidentifier... – the command list is executed in a subshell, i.e. () instead of {}. Example functionËidentifierË(command_list) identifierË()Ë(command_list) Syntax timeËpipeline The commands in pipeline are executed and the elapsed time and the user and system time are reported on standard error. The following reserved words are only recognized as the first word of a command and when not quoted: if select time 44 then while [[ elif until ]] else do fi done case { esac } for function U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Comments 2.3.10 Comments A word beginning with the hash character # causes that word and all the following characters in the line to be ignored. 2.3.11 Aliasing If the first word of a command is a defined alias, it is replaced by the text of the alias. An alias name consists of any number of characters excluding metacharacters, quoting characters, file expansion characters, parameter and command substitution characters, and the equal sign =. The replacement string can contain any valid POSIX shell script including the metacharacters listed above. The first word of each command in the replaced text will in turn be tested for aliases. If the last character of the alias value is a blank, the word following the alias will also be checked for alias substitution. Aliases can be used to redefine built-in commands but cannot be used to redefine the reserved words listed above. Aliases can be created, exported and listed on standard output with the alias command and can be removed with the unalias command. Exported aliases remain in effect for scripts invoked by name, but must be reinitialized for separate invocations of the POSIX shell. Aliases are frequently used as a short hand for full path names. An option to the built-in alias command allows the value of the alias to be automatically set to the full path name of the corresponding command. These aliases are called tracked aliases. The value of a tracked alias is defined the first time the corresponding command is looked up and becomes undefined each time the PATH variable is reset. These aliases remain tracked so that the next reference will redefine the value. Several tracked aliases are compiled into the POSIX shell. The -h option of the built-in set command makes each referenced command name into a tracked alias. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Aliasing is performed when scripts are read, not while they are being executed. Thus for an alias to take effect the alias definition command has to be executed before the command which references the alias is read. U22794-J-Z125-6-76 45 Tilde substitution Entering commands from the POSIX shell The following exported aliases are compiled into the POSIX shell but can be unset or redefined with unalias. autoload='typeset -fu' false='let 0' functions='typeset -f' hash='alias -t' history='fc -l' integer='typeset -i' nohup='nohupË' r='fc -e -' true=':' type='whence -v' Example The following aliases could be defined to construct l, ll and lf: alias l='/bin/ls -m' alias ll='/bin/ls -l' alias lf='/bin/ls -CF' 2.3.12 Tilde substitution After alias substitution is performed, each word is checked to see if it begins with an unquoted ~ (tilde). If it does, then the word up to the next / (slash) is checked to see if it matches a login name in the /etc/passwd file. If a match is found, the tilde and the matched login name are replaced by the login directory of the matched user. This is called a tilde substitution. If no match is found, the original text is left unchanged. A tilde by itself, or in front of a slash, is replaced by $HOME. A tilde followed by a plus sign or a minus sign is replaced by $PWD and $OLDPWD, respectively. In addition, tilde substitution is attempted when the value of a "variable assignment" begins with a ~. Example The command cat ~/.profile allows you to edit the .profile file in your login directory from any location in your file tree. 46 U22794-J-Z125-6-76 Command substitution 2.3.13 Command substitution There are two ways of substituting the standard output of a command for a part of a word or a full word. In the first (new) form, the command is enclosed in parentheses and preceded by a dollar sign: $(...). In the second (old) form, the command is enclosed within backquotes: ` ...` . If the second form is used, the string between the backquotes is processed for special quoting characters before the command is executed (see the section “Quoting metacharacters” on page 55). Trailing newlines are removed for both forms. 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell The command substitution $(cat file) can be replaced by the equivalent but faster $( all tail $_ ! The process number of the last command invoked as a background process. ERRNO The value of errno as set by the most recently failed system call. This value is systemdependent and is intended for debugging purposes. LINENO The line number of the current line within the script or function being executed. OLDPWD The previous working directory set by the cd command. OPTARG The value of the last option argument processed by the built-in getopts command. OPTIND The index of the last option argument processed by the built-in getopts command. PPID The process number of the parent of the current POSIX shell. PWD The present working directory set by the cd command. RANDOM Each time this variable is referenced, a random integer, uniformly distributed between 0 and 32767, is generated. You can initialize the sequence of random numbers by assigning a numeric value to RANDOM. 50 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Shell variables and parameter substitution REPLY This variable is set by the select statement and by the built-in read command when no arguments are supplied. SECONDS Each time this variable is referenced, the number of seconds since the invocation of the POSIX shell is returned. If this variable is assigned a value, the value returned upon reference will be the value that was assigned plus the number of seconds since the assignment. The following variables are used by the POSIX shell: CDPATH The search path for the cd command. COLUMNS If this variable is set, then its value is used to define the width of the editing window when the POSIX shell is in edit mode as well as for outputting the select list. This variable is of use when the POSIX shell is accessed via rlogin. EDITOR If the value of this variable ends with vi and if the variable VISUAL is not set then the corresponding option is set (see set). This variable is of use when the POSIX shell is accessed via rlogin. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 ENV If this variable is set then it contains the path name of the procedure which is executed when the POSIX shell is called. This procedure is mostly used for function and alias definitions. The value of this variable is used to perform parameter substitution for file name generation. FCEDIT The name of the standard editor for the built-in fc command. The only value which is currently permissible for this variable is edt. FPATH The search path for function definitions. This path is used when a function having the attribute -u is accessed and no command is found. If an executable file is found then it is read and executed in the current environment. HISTFILE If this variable is set when the POSIX shell is invoked, its value is the path name of the file that will be used to store the command history (see the section “Command re-entry” on page 65). U22794-J-Z125-6-76 51 Shell variables and parameter substitution Entering commands from the POSIX shell HISTSIZE If this variable is set when the POSIX shell is invoked, the shell will remember the commands you enter (command history). The number of previously entered commands that are accessible by this shell will be greater than or equal to the given number. The default is 128. HOME The default argument (home directory) for the cd command. IFS The POSIX shell’s internal field separator, used to separate command words which result from command or parameter substitution and to separate words with the built-in read command. The value of IFS is normally set to space, tab, and newline. The first character of the IFS variable is used to separate arguments in "$*" substitutions (see the section “Quoting metacharacters” on page 55). IO_CONVERSION If this variable is set to YES, and if POSIX commands (e.g. awk, cat, grep etc.) are being used to access files in a (mounted) ASCII file system, then conversion is performed automatically. LINES If this variable is set, its value is to determine the column length for printing select lists. select lists will print vertically until about two-thirds of LINES lines are filled. MAIL If this variable is set to the name of a mail file and the MAILPATH variable is not set, the shell informs you of the arrival of mail in the specified file. MAILCHECK The value of this variable specifies how often (in seconds) the POSIX shell should check for changes in the modification time of any of the files specified by the MAILPATH or MAIL variables. The default value for MAILCHECK is 600 seconds. When the specified time has elapsed, the POSIX shell checks the mail files before issuing the next prompt. MAILPATH A colon-separated list of file names. If this variable is set, the shell informs you of any modifications to the specified files that have occurred within the last MAILCHECK seconds. Each file name may be followed in the list by a question mark and a message that is to be printed. The message will undergo parameter substitution, with the variable $_ defined as the name of the file that has changed. The default message is: "you have mail in $_". PATH The search path for commands (see Execution). You may not change the value of this variable if you are using a restricted POSIX shell. 52 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Shell variables and parameter substitution PS1 The value of this variable is expanded for parameter substitution in order to define the prompt used by the POSIX shell. The default value is “$Ë” or, in the case of privileged users, “#Ë”. The use of an exclamation mark ! in the prompt is replaced by the command number (see the section “Command re-entry” on page 65). PS2 Secondary prompt string displayed by the POSIX shell when further input is expected after a newline character. The default is “>Ë”. PS3 Prompt string used within a select loop to prompt for the desired number. The default is “#?Ë”. PS4 The value of this variable is expanded for parameter substitution and precedes each line of an execution trace. The default execution trace prompt is “+Ë”. SHELL The path name of the POSIX shell is stored in the environment. When called, the POSIX shell acts as a restricted shell if the pattern *r*sh* matches the file name component of the path name (see section “basename return non-directory portion of path name” on page 149). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 TMOUT If TMOUT is set to a value greater than zero, the POSIX shell will automatically terminate if a command is not entered within the prescribed number of seconds after issuing the PS1 prompt. (Caution: the POSIX shell may have been compiled with a maximum bound for this value which cannot be exceeded). VISUAL If the value of this variable ends with vi then the corresponding option is se (see section “Built-in POSIX commands” on page 36). This variable is of use when the POSIX shell is accessed via rlogin. The POSIX shell assigns default values to the following variables: PATH, PS1, PS2, PS3, PS4, MAILCHECK, TMOUT and IFS. The variables HOME, MAIL and SHELL are set by the command /START-POSIX-SHELL. 2.3.15 Blank interpretation After parameter and command substitution, the results of substitutions are scanned for field separator characters and split into distinct arguments where such characters are found. Explicit null arguments (e.g. "" or ’’) are retained. Implicit null arguments (those resulting from parameters that have no values) are removed. U22794-J-Z125-6-76 53 File name generation Entering commands from the POSIX shell 2.3.16 File name generation After these various substitutions, each word is examined for the presence of an asterisk *, question mark ? or left-hand square bracket [. However, this examination is only performed if the option -f (see set) has not been set. If one of these characters is found in a word then the word is considered as a pattern. The word is then replaced by lexicographically sorted file names which match the pattern. If no matching file name is found for the pattern then the word is retained unchanged. If you use patterns for file name generation you must pay special attention to the characters period . and slash /: a period at the start of a file name or immediately after a /, as well as / itself must match explicitly. The special handling of these characters does not apply to other substitutions. * matches any string, including the null string. ? matches any single character. (Slashes and dots are treated specially; see above.) [...] matches any one of the characters enclosed within the square brackets. A pair of characters separated by a dash (-) matches any character lexically between the pair, inclusive. A dash can be included in the set of characters to be matched as long as it is the first or last character. If the first character following the left bracket is a an exclamation point, the enclosed set of characters is negated: any character not enclosed is matched. A pattern list is a list of one or more patterns separated from each other by a | (vertical bar). Composite patterns can be formed with one or more of the following constructs: ?(pattern-list) Optionally matches any one occurrence of the given patterns. *(pattern-list) Matches zero or more occurrences of the given patterns. +(pattern-list) Matches one or more occurrences of the given patterns. @(pattern-list) Matches exactly one of the given patterns. !(pattern-list) Matches anything, except one of the given patterns. 54 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Quoting metacharacters 2.3.17 Quoting metacharacters A metacharacter is one of the following characters: ; & ( ) | < > space tab newline-character A blank is either a tab or space. An identifier consists of a string of letters, digits and the underscore character _. This string must begin with a letter or underscore. Identifiers are used as names for functions and variables. A word is a string of characters which are separated by one or more metacharacters. Each of the metacharacters has a special meaning for the POSIX shell and is used as a word separator unless quoted. Quote Meaning \ A metacharacter preceded by a backslash \ is quoted and therefore stands for itself. The pair \new-line-character is ignored or deleted by the POSIX shell. ’...’ All characters which are enclosed in apostrophes ’...’ are quoted. However, a pair of apostrophes may not enclose a single apostrophe. "..." Strings which are enclosed in quotes "..." are subject to parameter and command substitution. When accompanied by a backslash they can be used to quote the backslash \, backquote ` , quotation mark " and dollar sign $. $* and $@ mean the same thing provided that they are not enclosed in quotes or used as a file name or as a value for variable assignment. Their meanings differ if they are used alone in quotes or if they used as command arguments. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 "$*" corresponds to "$1Ë$2Ë..." if Ë is the value of the first character of the variable IFS, and "$@" stands for "$1"Ë"$2"Ë..., that is to say that the individual call arguments are retained. ` ...` Strings which are enclosed in backquotes ` ...` can be quoted by using the backslash \, backquotes ` and the dollar sign $. If the whole string needs to be enclosed in quotation marks "...` ...` ..." you can use the backslash \ to quote the quotation mark ". The special meaning of reserved words or aliases can be removed by quoting any character of the reserved word. However, it is also sufficient to entire a single "\" before the name in order to quote the entire word (e.g. "\while"). The recognition of function names or built-in command names cannot be suppressed in this way. U22794-J-Z125-6-76 55 Arithmetic evaluation Entering commands from the POSIX shell 2.3.18 Arithmetic evaluation The built-in let command provides a mechanism for performing integer arithmetic. Evaluations are performed using long arithmetic. Constants are of the form [base#]n, where base is a decimal number between two and thirty-six representing the arithmetic base: n is a number in that base. If base# is omitted, base 10 is used. An arithmetic expression uses much the same syntax, precedence, and associativity as the C language. All the integral operators, other than ++, --, ?, : and the comma are supported. Variables can be referenced by name within an arithmetic expression without using the parameter substitution syntax (the $ character). When a variable is referenced, its value is evaluated as an arithmetic expression. An internal integer representation of a variable can be specified as an attribute with the -i option of the built-in typeset command. Arithmetic evaluation is performed on the value of each assignment to a variable with the -i attribute. If you do not specify an arithmetic base, the first assignment to the variable determines the arithmetic base. This base is used when parameter substitution is performed. Since many of the arithmetic operators must be quoted for the POSIX shell, an alternative form of the let command is provided. For any command which begins with a double left parenthesis ((, all the characters until a matching double right parenthesis )) are treated as a quoted expression. Thus ((a=a+b)) is equivalent to let "a=a+b". 56 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Conditional expressions 2.3.19 Conditional expressions A conditional expression can be used to test attributes of files and to compare algebraic expressions and strings. In the POSIX shell, conditional expressions are specified as part of a compound command of the form [[...]]. Blank interpretation and file name generation are not performed on the words of the conditional expression between [[ and ]]. Each conditional expression can be constructed from one or more of the following unary or binary expressions: In each of the expressions below, if file is of the form /dev/fd/n, where fd is the file descriptor and n is an integer, then the test is applied to the open file whose descriptor number is n. -aËfile (access) True if file exists. -bËfile (block device) True if file exists and is a block special file. -cËfile (character device) True if file exists and is a character special file. -dËfile (directory) True if file exists and is a directory. -fËfile (file) True if file exists and is an ordinary file. -gËfile (group ID) True if file exists and has its set-group-ID bit set. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -kËfile (sticky) True if file exists and is has its sticky bit set. -oËoption (option) True if the named option is turned on (option can be set with set). You must use the full option name, e.g. errexit. -pËfile (pipe) True if file exists and is a FIFO special file or a pipe. -rËfile (read) True if file exists and the current process has read permission for it. -sËfile (size) True if file exists and has a size greater than zero. -tËfiledes (terminal) True if file descriptor number fildes is open and is associated with a terminal. -uËfile (user ID) True if file exists and has its set-user-ID bit set. U22794-J-Z125-6-76 57 Strings, Algebraic integer comparisons Entering commands from the POSIX shell -wËfile (write) True if file exists and the current process has write permission for it. -xËfile (execute) True if file exists and the current process has execute permission for it. If file exists and is a directory, then the current process must have permission to search in the directory. -GËfile (group) True if file exists and its group matches the effective group ID of the current process. -LËfile (symbolic link) True if file exists and is a symbolic link. -OËfile (owner) True if file exists and is owned by the effective user ID of the current process. -SËfile (socket) True if file exists and is a socket. file1Ë-ntËfile2 (newer than) True if file1 exists and is newer than file2. file1Ë-otËfile2 (older than) True if file1 exists and is older than file2. file1Ë-efËfile2 (equal file) True if file1 and file2 exist and are links to the same file. String attributes and comparisons -nËstring (non-zero) True if string exists and is not a null string, i.e. if the length of the string is greater than 0. -zËstring (zero) True if the specified string is a null string, i.e. if the length of the string is 0. stringË=Ëpattern True if string matches pattern. stringË!=Ëpattern True if string does not match pattern. string1Ë<Ëstring2 True if string1 comes before string2 in the EBCDIC collating sequence. string1Ë>Ëstring2 True if string1 comes after string2 based in the EBCDIC collating sequence. 58 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Strings, Algebraic integer comparisons Algebraic comparisons between integers expr1Ë-eqËexpr2 (equal) True if expr1 is equal to expr2. expr1Ë-neËexpr2 (not equal) True if expr1 is not equal to expr2. expr1Ë-ltËexpr2 (less than) True if expr1 is less than expr2. expr1Ë-gtËexpr2 (greater than) True if expr1 is greater than expr2. expr1Ë-leËexpr2 (less than or equal) True if expr1 is less than or equal to expr2. expr1Ë-geËexpr2 (greater than or equal) True if expr1 is greater than or equal to expr2. Negated and compound expressions A compound expression can be constructed from the above expressions with any of the following mechanisms. The mechanisms are listed in decreasing order of precedence: (ËexpressionË) True if expression is true. The enclosed expression can be a single expression or a group of concatenated expressions. expression1Ë&&Ëexpression2 Logical AND: True if expression1 and expression2 are both true. expression1Ë||Ëexpression2 Logical OR: True if either expression1 or expression2 is true. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 !Ëexpression Negation: true if expression is false. U22794-J-Z125-6-76 59 Process environment Entering commands from the POSIX shell 2.3.20 Environment The environment of a process consists of a list of name=value pairs that is passed to an executed program in the same way as a normal argument list. The names must be POSIX shell-style identifiers; the values must be character strings (including the null string). The POSIX shell interacts with the environment in several ways. On invocation, the shell scans the environment and creates a variable for each name found, giving it the corresponding value and marking it for export. Executed commands inherit the environment. If the user modifies the values of these variables or creates new ones using the export or typeset -x commands, they become part of the environment. The environment seen by any executed command is thus composed of any name=value pairs originally inherited by the shell, whose values may be modified by the current shell, plus any additions that have been marked in export or typeset -x commands. The environment for any simple command or function may be augmented by prefixing it with one or more variable assignments. A variable assignment argument is a word of the form identifier=value. command sees the following lines as equivalent: TERM=450 command arguments ( export TERM ; TERM=450 ; command arguments ) If the -k option was set on POSIX shell invocation or with the built-in set command, all variable assignment arguments are exported to the environment, even if they occur after the command name. 60 U22794-J-Z125-6-76 Functions 2.3.21 Functions The reserved word function (see section “Compound commands” on page 41) is used to define POSIX shell functions. Shell functions are read in and stored internally. Alias names are resolved when the function is read. Functions are executed like commands, with arguments passed as positional parameters (see section “Execution” on page 64). 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Functions execute in the same process as the caller and share all open files and the present working directory with the caller. Traps caught by the caller are reset to their default action inside the function. A trap condition that is not caught or ignored by the function causes the function to terminate; the condition is then passed on to the caller. A trap on EXIT set inside a function is executed after completion of the function in the environment of the caller. Variables are usually shared between the calling program and the function. However, the built-in typeset command can be used within a function to define local variables whose scope includes the current function and all functions it calls. The built-in return command is used to return from function calls. Errors that occur within functions return control to the caller. Function identifiers or names can be listed with the -f or +f option of the built-in typeset command. The text of functions may also be listed with the -f option. Functions can be undefined with the -f option of the built-in unset command. Functions are usually not accessible when the POSIX shell executes a shell script. Example The following function named lh lists the top two levels of the directory hierarchy in which you are located or which you specify as an argument. Regular files are ignored as arguments. function lh { for i in ${*:-.} do if [[ -d $i ]] then print $i: cd $i ls -CF $( ls ) cd - >/dev/null fi done } Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The -xf option of the typeset command allows a function to be marked for export. These functions can then be used in scripts that are executed without a separate invocation of the POSIX shell. Functions that need to be defined across separate invocations of the shell should be specified in the ENV file with the -xf option of typeset. U22794-J-Z125-6-76 61 Jobs Entering commands from the POSIX shell The for loop processes each of the specified arguments in succession. If you have not specified an argument, $* is set to the current directory (.). If a directory is present, its name and contents are listed as follows: cd $i switches to the directory to be listed; $( ls ) is replaced by the content of the directory $i, and ls -CF directory_list lists the files, followed by the contents of the directories, with flags to indicate executables and directories. The subsequent cd command silently returns to the initial directory (before the first cd $i). 2.3.22 Jobs If the monitor option of the built-in set command is turned on (set -m), an interactive POSIX shell associates a job with each pipeline. It maintains a table of current jobs, which you can written to standard output with the built-in jobs command, and assigns them small integer numbers. When a job is started asynchronously with &, the shell prints a line of the form: [1] 1234 indicating that the job which was started asynchronously was job number 1 and had one (top-level) process, whose process ID was 1234. If you use rlogin to access the POSIX shell (the following key combinations are supported only on character-mode terminals): If you want to start other processes while an existing process is being executed then you simply need to press the key combination [CTRL][Z]. This causes a STOP signal to be sent to the process which is currently running. The POSIX shell then indicates that the job has been stopped and issues a prompt. You may then modify the status of this job: you can use the built-in command bg (background) to run the job in background mode, leave it stopped while you execute other commands or retrieve it to the foreground using the built-in command fg (foreground). [CTRL][Z] is processed as soon as it is pressed and its effect is similar to that of the interrupt key combination [CTRL][D]. Inputs which have not yet been read and outputs which have not yet been displayed are discarded. There are several ways to reference jobs in the shell. A job can be referenced by the process ID of any process or by one of the following expressions: %number the job with the given job number. %string any job whose command line begins with string. %?string any job whose command line includes string. 62 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Signals %% the current job. %+ equivalent to %% %the previous job. The POSIX shell registers changes in the status of jobs immediately. It normally informs you whenever a job becomes blocked so that no further progress is possible, but only just before it prints a prompt. This is done so that it does not otherwise disturb your work. When the monitor option is turned on, each background job that completes triggers any trap set for CHLD. If you try to exit the POSIX shell while jobs are running in the background or stopped, you will be warned with a message. You may then use the jobs command to obtain an overview of the current situation. If you do this or immediately try to exit again, the shell will not warn you a second time, and the stopped jobs will be terminated. 2.3.23 Signals Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The INT and QUIT signals for an invoked background command (&) are ignored if the job monitor option is not active. Otherwise, signals have the values inherited by the POSIX shell from its parent (see also the built-in trap command). U22794-J-Z125-6-76 63 Execution Entering commands from the POSIX shell 2.3.24 Execution Each time a command is executed, the substitutions described above are carried out in the following order: – quoting – parameter substitution – tilde substitution – aliasing – file name generation – I/O redirection – command substitution If the command name matches the name of one of the built-in commands, it is executed within the current POSIX shell process. Next, the command name is checked to see if it matches one of the user-defined functions. If it does, the positional parameters are saved and then reset to the arguments of the function call. When the function completes or executes a built-in return command, the positional parameter list is restored and any trap set on EXIT within the function is executed. The exit status is that of the last command executed in the function. A function is also executed in the current POSIX shell process. If a command name is not a built-in command or a user-defined function, a process is spawned and an attempt is made to execute the command via the system call exec. The shell variable PATH defines the search path for the directory containing the command. Alternative directory names are separated by a colon (:). The default path is /usr/bin: (specifying /usr/bin and the current directory in that order). The current directory can be specified by two or more adjacent colons, or by a colon at the beginning or end of the path list. If the command name contains a slash, the search path is not used. Otherwise, each directory in the path is searched for an executable file. If the file has execute permission but is not a directory or an a.out file, it is assumed to contain a shell script. A subshell is spawned to read it. Any non-exported aliases, functions and variables are removed in this case. A parenthesized command is executed in a sub-shell without removing non-exported quantities. 64 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Entering commands from the POSIX shell Command re-entry 2.3.25 Command re-entry The text of the last HISTSIZE commands entered from a terminal is saved in a history file. The default value for HISTSIZE is 128. If the HISTFILE variable is not set or if the file denoted by its value is not writable, the file $HOME/.sh_history is used to save the command history. A POSIX shell can access the commands of all interactive shells which use the same history file. The built-in fc command can be used to list or edit a portion of this file. The portion of the file to be edited or listed can be selected by number or by giving the first character or characters of the command. A single command or range of commands may be specified. If you do not specify an editor program as an argument to fc, the value of the variable FCEDIT is used. If FCEDIT is not defined, /usr/bin/ed is used. The edited commands are printed and re-executed when you leave the editor. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The editor name - (if FCEDIT=-) is used to skip the editing phase and to directly re-execute the command. In this case a substitution variable of the form old=new can be used to modify the command before execution. For example, if r is aliased to fc -e -, then typing r bad=good c will re-execute the most recent command which starts with the letter c, replacing the first occurrence of the string bad with the string good. U22794-J-Z125-6-76 65 Command summary Working with the POSIX shell 2.4 Command summary The summaries below provide ● an overview of all POSIX commands in the POSIX shell ● an overview according to functions There are also commands which can be entered from within the POSIX shell but which are not described in this manual, for example the commands cc or c89 which are used to call a compiler (for a description see the “C/C++ (BS2000/OSD)” manual [5]). 2.4.1 Summary of all commands of the POSIX shell The POSIX shell comprises the basic shell (POSIX-BC) and the extended shell (POSIX-SH). It contains the POSIX commands found in the following table. Entries in the Type column describe the command type: bin separate module blt built-in in the shell Apart from these commands, there are also some additional built-in commands (such as for, while, if, break, etc.), which are described in the section “Compound commands” on page 41ff. scr script The column LFS describes whether the commands can process large POSIX files: A (large file aware): uses large files correctly S (large file safe): recognizes large files but rejects processing in a defined manner Name Location Type Delivery Description adduser /sbin bin SINLIB.POSIX-BC.ROOT Assign individual user number alias /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Define or display alias ar /usr/bin bin SINLIB.POSIX-BC.SHELL Administer libraries LFS S asa /usr/bin bin SINLIB.POSIX-SH Convert control characters for positioning at /usr/bin bin SINLIB.POSIX-SH Execute commands at a later date Programmable processing of text files awk /usr/bin bin SINLIB.POSIX-SH basename /usr/bin scr SINLIB.POSIX-BC.SHELL Separate file name from path batch /usr/bin scr SINLIB.POSIX-BC.SHELL Execute commands at a later date bc /usr/bin bin SINLIB.POSIX-SH 66 A Arithmetic language U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary Name Location Type Delivery Description LFS bg - blt SINLIB.POSIX-BC.SHELL Process jobs in background bs2cmd - blt SINLIB.POSIX-BC.SHELL Execute BS2000 command bs2cp /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Copy BS2000 files bs2do /usr/bin bin SINLIB.POSIX-BC.SHELL Calling BS2000 procedures from POSIX bs2file /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Define file attributes for BS2000 files bs2lp /usr/bin bin SINLIB.POSIX-BC.SHELL Print files bs2pkey /usr/bin bin SINLIB.POSIX-BC.SHELL Assign P keys cal /usr/bin bin SINLIB.POSIX-SH Display calendar cancel /usr/bin bin SINLIB.POSIX-SH Delete print jobs cat /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Concatenate and output files A cd /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Change current directory A chgrp /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Change group number of file A A chmod /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Change access rights A chown /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Change owner of file A cksum /usr/bin bin SINLIB.POSIX-SH Write checksums and file sizes A cmp /usr/bin bin SINLIB.POSIX-SH Compare files character by character A Search for identical lines in two sorted files S comm /usr/bin bin SINLIB.POSIX-SH command /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Execute simple command compress /usr/bin bin SINLIB.POSIX-SH cp /sbin blt+bin SINLIB.POSIX-BC.SHELL Copy files A cp /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Copy files A A Compress files A cpio /usr/bin bin SINLIB.POSIX-BC.SHELL Swap files and directories in and out crontab /usr/bin bin SINLIB.POSIX-SH csplit /usr/bin bin SINLIB.POSIX-SH Split file according to specific criteria S cut /usr/bin bin SINLIB.POSIX-SH Cut bytes, characters or fields from the lines of a file S date /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Display time and date dd /sbin bin SINLIB.POSIX-SH Copy and convert files debug /usr/bin bin SINLIB.POSIX-BC.ROOT Test POSIX programs df /sbin bin SINLIB.POSIX-BC.SHELL Display number of free and occupied disk blocks A A Execute commands at regular intervals diff /usr/bin bin SINLIB.POSIX-SH dirname /usr/bin scr SINLIB.POSIX-BC.SHELL Separate path prefix from file name du /usr/bin bin SINLIB.POSIX-BC.SHELL Display occupied memory space dumpfs /sbin bin SINLIB.POSIX-BC.ROOT echo /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Output call arguments ed /sbin bin SINLIB.POSIX-SH edt - blt SINLIB.POSIX-BC.SHELL Call BS2000 file editor EDT U22794-J-Z125-6-76 Compare files line by line S A Display internal file system information Line editor in interactive mode S 67 Command summary Working with the POSIX shell Name Location Type Delivery Description LFS egrep /usr/bin SINLIB.POSIX-SH Find pattern S Change environment when executing commands bin env /usr/bin bin SINLIB.POSIX-SH eval - blt SINLIB.POSIX-BC.SHELL Process call arguments and execute them as commands ex /usr/bin bin SINLIB.POSIX-SH exec - blt SINLIB.POSIX-BC.SHELL Overlay current shell exit - blt SINLIB.POSIX-BC.SHELL Terminate shell procedure expand /usr/bin bin SINLIB.POSIX-SH export - blt SINLIB.POSIX-BC.SHELL Export shell variables expr /sbin blt+bin SINLIB.POSIX-BC.SHELL Evaluate expressions expr /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Evaluate expressions false /usr/bin alias+scr SINLIB.POSIX-BC.SHELL Return end status not equal to 0 Line editor Convert tab character to blanks S fc /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Access to history file fg - blt SINLIB.POSIX-BC.SHELL Bring jobs into foreground fgrep /usr/bin bin SINLIB.POSIX-SH Find strings S file /usr/bin bin SINLIB.POSIX-SH Define file type A find /usr/bin bin SINLIB.POSIX-SH Search directories A fold /usr/bin bin SINLIB.POSIX-SH Split up long lines S fsck /sbin bin SINLIB.POSIX-BC.ROOT Check consistency of file system and correct interactively with user fsexpand /sbin bin SINLIB.POSIX-BC.ROOT Expand existing file systems ftyp /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Define types of file processing (BS2000) gencat /usr/bin bin SINLIB.POSIX-SH Generate binary coded message catalog A genso /usr/bin bin SINLIB.POSIX-BC.ROOT Generate shared object getconf /usr/bin bin SINLIB.POSIX-SH Call up configuration values getopts /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Search procedure arguments for options grep /sbin bin SINLIB.POSIX-BC.SHELL Get pattern hash /usr/bin alias+scr SINLIB.POSIX-BC.SHELL Process shell hash table hd /usr/bin bin SINLIB.POSIX-BC.ROOT Hex dump A head /usr/bin bin SINLIB.POSIX-SH Output start of a file A iconv /usr/bin bin SINLIB.POSIX-BC.SHELL Convert code id /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Output user identification inetd /usr/sbin bin SINLIB.POSIX-BC.ROOT Daemon for internet services info /sbin bin SINLIB.POSIX-BC.ROOT Online diagnostic tool A A A ipcrm /usr/bin bin SINLIB.POSIX-BC.ROOT Remove setup for interprocess communications ipcs /usr/bin bin SINLIB.POSIX-BC.ROOT Output state of interprocess communications setup 68 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary Name Location Type Delivery Description jobs - blt SINLIB.POSIX-BC.SHELL Output job information join /usr/bin bin SINLIB.POSIX-SH kill /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Send signals to processes Merge two files according to matching fields lc /usr/bin bin SINLIB.POSIX-BC.SHELL Output information on directories and files let - blt SINLIB.POSIX-BC.SHELL Integer arithmetic lex /usr/bin bin SINLIB.POSIX-SH ln /sbin blt+bin SINLIB.POSIX-BC.SHELL Enter reference to file LFS A Create scanner locale /usr/bin bin SINLIB.POSIX-SH Call up information on the locale localedef /usr/bin bin SINLIB.POSIX-SH Define locale logger /usr/bin bin SINLIB.POSIX-SH Log messages logname /usr/bin bin SINLIB.POSIX-SH Query login name lp /usr/bin bin SINLIB.POSIX-SH Print out files Output information on print jobs A lpstat /usr/bin bin SINLIB.POSIX-SH ls /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Output information on directories and files mailx /usr/bin bin SINLIB.POSIX-SH Interactively process messages make /usr/bin bin SINLIB.POSIX-SH Manage groups of files man /usr/bin scr SINLIB.POSIX-SH Use online documentation mesg /usr/bin bin SINLIB.POSIX-SH Forbid or permit receipt of messages mkdir /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Create directory mkfifo /usr/bin bin SINLIB.POSIX-SH Create FIFO mkfs /sbin bin SINLIB.POSIX-BC.ROOT Create file system mknod /sbin bin SINLIB.POSIX-BC.ROOT Create device file A more /usr/bin bin SINLIB.POSIX-SH Control screen output A mount /sbin bin SINLIB.POSIX-BC.ROOT Mount file systems and remote resources mountall /sbin scr SINLIB.POSIX-BC.ROOT Mount two or more file systems mv /sbin blt+bin SINLIB.POSIX-BC.SHELL Move or rename files newgrp /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Modify group membership nice /usr/bin bin SINLIB.POSIX-SH Change priority of commands nl /usr/bin bin SINLIB.POSIX-SH Number text lines A A A S nm /usr/bin bin SINLIB.POSIX-SH Output an object file symbol table nohup /usr/bin bin SINLIB.POSIX-SH Execute command and ignore signals od /usr/bin bin SINLIB.POSIX-SH Output file contents in octal format S paste /usr/bin bin SINLIB.POSIX-SH Merge lines S patch /usr/bin bin SINLIB.POSIX-SH Use difference report Check path names pathchk /usr/bin bin SINLIB.POSIX-SH pax /usr/bin bin SINLIB.POSIX-BC.SHELL Process portable archives U22794-J-Z125-6-76 A 69 Command summary Working with the POSIX shell Name Location Type Delivery Description pdbl /usr/bin SINLIB.POSIX-BC.ROOT Administer private POSIX loader bin LFS pkginfo /usr/bin bin SINLIB.POSIX-BC.ROOT Display information about software packages posdbl /usr/sbin bin SINLIB.POSIX-BC.ROOT Administer POSIX loader Format files and output to standard output pr /usr/bin bin SINLIB.POSIX-SH print - blt SINLIB.POSIX-BC.SHELL Output mechanism similar to echo printf /usr/bin blt+bin SINLIB.POSIX-SH ps /sbin bin SINLIB.POSIX-BC.SHELL Query process data pwd /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Output path name of current working directory rcp /usr/bin bin SINLIB.POSIX-BC.INET read /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Read arguments of standard input and assign shell variables readonly - blt SINLIB.POSIX-BC.SHELL Protect shell variables Formatted output Copy files from or to a remote computer renice /usr/bin bin SINLIB.POSIX-SH rm /sbin blt+bin SINLIB.POSIX-BC.SHELL Delete files rmdir /sbin blt+bin SINLIB.POSIX-BC.SHELL Delete directories rmpart /sbin bin SINLIB.POSIX-BC.ROOT Change priority of current processes A Remove partition rsh /usr/bin bin SINLIB.POSIX-BC.INET Execute commands on remote computer sed /usr/bin bin SINLIB.POSIX-SH Editor in procedure mode set - blt SINLIB.POSIX-BC.SHELL Set options or parameters, output variables settime /usr/bin bin SINLIB.POSIX-BC.SHELL Set shell options or positional parameters sh /sbin bin SINLIB.POSIX-BC.SHELL POSIX shell command interpreter and programming language shift - blt SINLIB.POSIX-BC.SHELL Move values of positional parameters to the left sleep /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Temporarily halt processes show_pubset_ /sbin export scr SINLIB.POSIX-BC.ROOT sort bin SINLIB.POSIX-BC.SHELL Sort and/or merge files /usr/bin A show file systems affected by EXPORT-PUBSET split /usr/bin bin SINLIB.POSIX-SH Distribute file across several files start_bs2fsd /sbin scr SINLIB.POSIX-BC.ROOT start copy daemons strings /usr/bin bin SINLIB.POSIX-SH Find printable strings in object or binary files stty /usr/bin bin SINLIB.POSIX-BC.ROOT Output or modify attributes of a data display station sum /usr/bin bin SINLIB.POSIX-SH Calculate checksum of a file sync /sbin bin SINLIB.POSIX-BC.ROOT Write back system cache tabs /usr/bin bin SINLIB.POSIX-SH Set tabulator stops tail /usr/bin bin SINLIB.POSIX-SH Output the last part of a file talk /usr/bin bin SINLIB.POSIX-SH Talk with another user tar /usr/bin bin SINLIB.POSIX-BC.SHELL Archive files 70 A A S A A A U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary Name Location Type Delivery Description tee /usr/bin bin SINLIB.POSIX-SH Join pipes together and copy input test /usr/bin blt-scr SINLIB.POSIX-BC.SHELL Check conditions time /usr/bin bin SINLIB.POSIX-BC.SHELL Measure command runtime times - blt SINLIB.POSIX-BC.SHELL Output total runtime of processes started up to now touch /usr/bin blt+bin SINLIB.POSIX-BC.SHELL Update modification and access times tput /usr/bin bin SINLIB.POSIX-SH tr /usr/bin bin SINLIB.POSIX-BC.SHELL Replace or delete character trap - blt SINLIB.POSIX-BC.SHELL Modify signal handling true /usr/bin alias+scr SINLIB.POSIX-BC.SHELL Return end status 0 tsort /usr/bin bin SINLIB.POSIX-SH Sort topologically tty /usr/bin bin SINLIB.POSIX-SH Output path name of current terminal type /usr/bin alias+scr SINLIB.POSIX-BC.SHELL Query command type typeset - blt SINLIB.POSIX-BC.SHELL Set attributes for shell variable ulimit /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Limit file size for writing or query current limit LFS A Initialize terminal or query terminfo database A A umask /usr/bin blt-scr SINLIB.POSIX-BC.SHELL Output or modify default allocation of access rights umount /sbin bin SINLIB.POSIX-BC.ROOT Unmount file systems and remote resources umountall /sbin scr SINLIB.POSIX-BC.ROOT Unmount two or more file systems unalias /usr/bin blt-scr SINLIB.POSIX-BC.SHELL Delete variables from alias tables uname /sbin bin SINLIB.POSIX-BC.ROOT Output basic data on the current operating system uname /usr/bin bin SINLIB.POSIX-BC.ROOT Output basic data on the current operating system uncompress /usr/bin bin SINLIB.POSIX-SH Uncompress compressed files A unexpand /usr/bin bin SINLIB.POSIX-SH Convert blanks to tab characters S uniq /usr/bin bin SINLIB.POSIX-BC.SHELL Search for repeated lines uudecode /usr/bin bin SINLIB.POSIX-SH Decode file after mailx transfer uuencode /usr/bin bin SINLIB.POSIX-SH Encode file for mailx transfer uuname /usr/bin bin SINLIB.POSIX-SH List names of system usp /usr/bin bin SINLIB.POSIX-BC.ROOT Dynamic setting of POSIX control parameters Screen editor vi /usr/bin bin SINLIB.POSIX-SH wait /usr/bin blt+scr SINLIB.POSIX-BC.SHELL Wait for termination of background processes wc /usr/bin bin SINLIB.POSIX-SH whence - blt SINLIB.POSIX-BC.SHELL Command localization who /sbin bin SINLIB.POSIX-SH Show active user IDs write /usr/bin bin SINLIB.POSIX-SH Send message to a user xargs /usr/bin bin SINLIB.POSIX-SH Create argument list(s) and execute command Count words, characters and lines yacc /usr/bin bin SINLIB.POSIX-SH Create parser zcat /usr/bin bin SINLIB.POSIX-SH Output compressed files U22794-J-Z125-6-76 A A 71 Command summary Working with the POSIX shell 2.4.2 Command summary according to functions The following summary indicates the function-specific subdivision of POSIX commands. Since some commands can be allocated to more than one function, it is possible that names may be duplicated. For a detailed description of the commands in alphabetical order please refer to the chapter “Commands” on page 91. The commands are allocated to the following main functions: 72 ● Command interpreter ● Querying or modifying the user environment ● Managing and processing files and texts – outputting – processing – saving and archiving – compressing and restoring to uncompressed state – querying and modifying file properties ● modifying and managing the file system – modifying the file system – managing the file system ● Printing and print management ● Data display terminal ● Editors ● Auxiliary commands for shell procedures ● Reading, converting and outputting characters ● Querying and modifying user properties ● User administration ● Interuser communication ● Calendar functions and dates ● Arithmetic functions ● Compiler commands ● Program testing ● Job management ● Process information ● Process control U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary ● Inter-process communication ● Terminal ● Checking storage availability ● Information on system data ● Online documentation ● Flushing the system buffer ● Calling BS2000 procedures ● Administer POSIX program cache ● Network commands ● NLS commands (Native Language System) Command interpreter sh POSIX shell Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Query or modify user environment adduser assign individual user IDs cd change working directory env set environment for command execution id return user identity logname display login name ls list directory contents pwd return working directory name tty output path name of current terminal who show who is on the system U22794-J-Z125-6-76 73 Command summary Working with the POSIX shell Managing and processing files and texts ● ● 74 output cat concatenate and print files hd hex dump head copy the first part of files more page through a text file od dump files in various formats pr prepare files for printing strings find printable strings in object or binary files tail copy the last part of a file zcat display compressed files in expanded form process awk pattern scanning and processing language cksum write file checksums and sizes cmp compare two files comm select or reject lines common to two sorted files csplit context split cut cut out selected fields of each line of a file diff differential file comparator edt process file with EDT (BS2000) egrep search a file with an ERE pattern fgrep search a file for a fixed-string pattern find find files fold filter for folding lines grep search a file for a pattern join relational database operator nl number lines paste merge corresponding or subsequent lines of files patch use diff list U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell ● Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 ● ● Command summary sort sort, merge or sequence check text files split split a file into pieces sum print checksum and block count of a file tr transliterate characters tsort topological sort uniq report or filter out repeated lines in a file wc word, line and byte or character count save and archive ar manage libraries cpio copy in and out dd convert and copy files iconv codeset conversion nm convert and copy files pax portable archive processing tar file archiver compressing and restoring to uncompressed state compress compress files uncompress expand compressed files zcat display compressed files in expanded form query and modify file properties chgrp change file group ownership chmod change file modes chown change file ownership file check type of file ls list directory contents touch change file access and modification times umask get or set the file mode creation mask U22794-J-Z125-6-76 75 Command summary Working with the POSIX shell Modifying and managing the file system ● ● modify file system bs2cp copy BS2000 files bs2file set BS2000 file attributes cp copy files csplit context split find find files fsexpand Expand existing file systems ftyp determine processing mode for BS2000 files ln link files make maintain groups of files mkdir make directory mv move files rm remove directory entries rmdir remove directories split split a file into pieces Manage file system dumpfs dump file system fsck file system check mkfifo make FIFO special file mknod make an inode mount mount a file system mountall mount file systems pathchk check pathnames show-pubset_export show file systems affected by EXPORT-PUBSET 76 start_bs2fsd start copy daemons umount unmount a file system umountall unmount file systems U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary Printing and print management asa interpret carriage-control characters bs2lp send files to a printer cancel cancel requests to an LP print service lp send requests to an LP print service lpstat print information about the status of the LP print pr prepare files for printing Editors ed interactive line editor edt process file with EDT (BS2000) ex command and display editor sed stream editor vi display editor (visual) basename return non-directory portion of path name dirname return directory portion of path name expr evaluate arguments as an expression false return false value © cognitas GmbH 2001-2007 getopts parse utility options athchk check pathnames sleep suspend execution for an interval Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 Auxiliary commands for shell procedures test evaluate expression true return true value xargs construct argument list(s) and execute command [Ë...Ë] evaluate expression U22794-J-Z125-6-76 77 Command summary Working with the POSIX shell Reading, converting and outputting characters echo write arguments to standard output hd hex dump od dump files in various formats print output mechanism similar to echo printf formatted output tee join pipes and make copies of input Querying and modifying user properties id return user identity logname display login name mesg permit or deny messages newgrp change to a new group User administration who show who is on the system Interuser communication mailx interactive message processing system (mail extended) mesg permit or deny messages talk talk to another user write write to another user Calendar functions and dates 78 at execute commands at a later time batch execute commands at a later time cal print calendar crontab regularly execute commands at specific times date write the date and time U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary Arithmetic functions bc arbitrary precision arithmetic language expr evaluate arguments as an expression let integer calculations Compiler commands lex generate programs for lexical tasks yacc yet another compiler-compiler Program testing debug test POSIX programs Job management bg run jobs in the background fg run jobs in the foreground jobs display status of jobs in the current session Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Process information logger log messages ps report process status time time a simple command times write process times Process control at / batch execute commands at a later time kill terminate or signal processes nice run a command at low priority (be nice) nohup run a command immune to hangups and quits renice alter the scheduling priority of running processes sleep suspend execution for an interval wait await process completion U22794-J-Z125-6-76 79 Command summary Working with the POSIX shell Inter-process communication ipcrm remove inter-process communication facilities ipcs inter-process communication status Data display terminal bs2pkey set P keys expand convert tabs to spaces stty display or modify attributes of a data display station tabs set tabs on a terminal tput initialize a terminal or query the terminfo database tty output path name of current terminal unexpand convert spaces to tabs Checking storage availability df report free disk space du estimate file space usage Information on system data info Online diagnostic tool pkginfo Display informations about software packages ps report process status uname output basic data on the current operating system who show who is on the system On-line pages man display on-line manual pages Clearing the system buffer sync 80 flush system buffer U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell Command summary Calling BS2000 procedures bs2do Calling BS2000 procedures from POSIX Administer POSIX program cache pdbl Administer private POSIX loader posdbl Administer POSIX loader Networking commands rcp remote file copy rsh remote shell uudecode decode file after mailing with mailx uuencode encode file for mailing with mailx uuname list names of UUCP systems NLS commands (Native Language System) gencat generate a binary encoded message catalog locale call up information about the locale localedef define locale Subsystem administration Dynamic setting of POSIX control parameters Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 usp U22794-J-Z125-6-76 81 Example Working with the POSIX shell 2.5 Example This section presents an example of operation using the POSIX shell. You log onto the BS2000, output the directory which corresponds to your user ID and start the POSIX shell. Once in the POSIX shell, you first create a .profile file in which you define alias variables to simplify operation and specify a new prompt which displays the current path at any given time as an aid to orientation. Once the .profile file has been executed, the definitions it contains take effect. You then transfer a file from the BS2000 file system to the POSIX file system where you process it. /set-logon-parameters user-id=user1,account=... ——————————————————————— /show-file-attributes ————————————————————————————————————————————————— % 114 :1OSN:$USER1.ANHANG.V2 % 3 :1OSN:$USER1.AVASQUER % 78 :1OSN:$USER1.BIB.EXAMPLES.SDF % 6 :1OSN:$USER1.DO.MSGCHECK % 5007 :1OSN:$USER1.FS.USER1 % 3 :1OSN:$USER1.MSG.PROT % 3 :1OSN:$USER1.OUTPUT % 3 :1OSN:$USER1.PROG.C % 3 :1OSN:$USER1.SYS.SDF.LOGON.USERPROC /start-posix-shell ———————————————————————————————————————————————————— POSIX Basisshell 07.0A41 created Jan 27 2009 POSIX Shell 07.0A41 created Jan 27 2009 Copyright (C) Fujitsu Technology Solutions 2009 All Rights reserved Last login: Wed Jan 28 12:31:24 2009 on term/004 —————————————————————— $ edt .profile ———————————————————————————————————————————————————————— 82 (1) (2) (3) (4) (5) (1) $ edt .profile Log on to the BS2000 as usual. (2) Use the BS2000 command SHOW-FILE-ATTRIBUTES to display the directory corresponding to your login name. (3) Use the BS2000 command START-POSIX-SHELL to call the POSIX shell. (4) You are accepted as a POSIX shell user. (5) Create the .profile file with the POSIX editor edt. Since the file does not exist, edt creates a new file (see page 83). U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k02 Working with the POSIX shell 1.00 alias ll='ls -l' 2.00 alias la='ls -al' 3.00 PS1='$PWD> ' 4.00 5.00 6.00 7.00 8.00 9.00 10.00 11.00 12.00 13.00 14.00 15.00 16.00 17.00 18.00 19.00 20.00 21.00 22.00 POSIX editor ready for file .profile: new file return LTG EM:1 Example 0000.00:001(0) TAST $ . .profile —————————————————————————————————————————————————————————— /home/user1> la ——————————————————————————————————————————————————————— total 84 drwxr-xr-x 5 USER1 USROTHER 2048 Dec 22 14:03 . drwxr-xr-x 63 SYSROOT POSSYS 2048 Dec 22 06:35 .. -rw-r--r-1 USER1 USROTHER 48 Dec 22 14:02 .profile -rw------1 USER1 USROTHER 2576 Dec 22 14:06 .sh_history drwxr-xr-x 2 USER1 USROTHER 2048 Dec 15 17:18 c-source drwxr-xr-x 2 USER1 USROTHER 8192 Dec 5 13:47 lost+found -rw-r--r-1 USER1 USROTHER 94 Dec 21 14:02 letter1 drwxr-xr-x 2 USER1 USROTHER 2048 Dec 19 15:05 test ... /home/user1> cd c-source —————————————————————————————————————————————— (6) (7) (8) (6) After creating the .profile file with edt and quitting the editor with the command return, you should evaluate the .profile file in the current shell. To do this, enter .profile. (7) The POSIX shell reports with the newly defined prompt which displays the current path /home/user1. You use the command for which the alias la has been defined to display all the files in the directory. (8) Change to the subdirectory c-source in which, for example, you store your C programs. U22794-J-Z125-6-76 83 Example Working with the POSIX shell /home/user1/c-source> bs2cp bs2:prog.c prog.c ————————————————————————— /home/user1/c-source> la total 60 drwxr-xr-x 2 USER1 USER1GRP 2048 Jul 6 . drwxr-xr-x 2 USER1 USER1GRP 2048 Jul 6 .. -rw-r--r-- 1 USER1 USER1GRP 2048 Jul 6 prog.c /home/user1/c-source> cat prog.c —————————————————————————————————————— #include main() { printf(“hello world\n“); return(0); } /home/user1/c-source> cc -o prog prog.c ——————————————————————————————— /home/user1/c-source> prog ———————————————————————————————————————————— hello world /home/user1/c-source> exit ———————————————————————————————————————————— .... —————————————————————————————————————————————————————————————————— /exit-job ————————————————————————————————————————————————————————————— 84 (9) (10) (11) (12) (13) (14) (15) (9) Copy the file prog.c, which is located in the BS2000 file system, to the POSIX file system. The file is written to the current directory, c-source. (10) Use cat to output the contents of the file prog.c. (11) Compile the file prog.c using the C compiler. You want the result of the compilation to be written to the file prog. (12) Run the program prog. It outputs the string “hello world” on screen. (13) Enter the command exit to terminate the POSIX shell. (14) You may enter further BS2000 commands if you so wish. (15) Log off from BS2000. U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k03 7. Juli 2009 Stand 11:58.25 3 International environment (NLS locale) 3.1 Native language support The most of the UNIX derivatives always used to be based on the ASCII coded character set, with American English as the language in which the user communicated with the computer. For the commercial market, however, it has always been essential to offer interactive programs communicating in the language of the program user (language in this sense being taken to include regional conventions such as currency formats); and as a result considerable extra effort was required to produce national variants of programs for other markets. The increasing international popularity of UNIX systems has now made it necessary to enhance the systems to cater flexibly for the differing scripts, languages and cultural conventions of its users. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 With NLS (the Native Language System) X/Open has defined an interface which makes it possible to – develop applications which communicate with the user in various native languages and conform to the associated local customs. Programs of this type make no assumptions about the language of the user and keep the data specifications separate from the program logic. Hence they are referred to as internationalized programs. – supply the correct native language and associated local customs to the runtime environment of an internationalized application. This technique is known as localization. Hence the set of conventions relating to local custom and language which applies in a given environment is referred to as the locale. The tools which NLS provides for these purposes include: – an announcement mechanism which enables users to identify their own native language, local custom and codeset requirements to programs at runtime. This mechanism works on the basis of environment variables. – message catalogs which allow program messages to be held apart from the program logic, translated into other languages and bound to the application at runtime. U22794-J-Z125-6-76 85 Native language support International environment (NLS locale) – internationalized C library functions which make no assumptions about native language, territory and codeset and are thus capable of handling universal character classification, case conversion (up/downshifting), number format conversion and string collation (sorting). – a set of C library functions which allow a personal language environment to be set, modified and disabled at program runtime. All the POSIX commands described in this manual are 8-bit transparent. That includes all the command-line arguments and all the data and characters interpreted by the commands. i There are, however, still certain restrictions on the portability of 8-bit data between POSIX and other systems: – Data interchange between systems over email links may be restricted to 7-bit data on account of the mail or networking protocols being used. – 8-bit data and file names may only be portable to systems which comply with the X/Open system interface definition. For detailed information on NLS refer to the “Programmer's Guide: Internationalization Localization” [13]. 86 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k03 International environment (NLS locale) Defining an internationalized environment 3.2 Defining an internationalized environment 3.2.1 The personal internationalized environment POSIX supports announcement mechanisms which allow settings for language, national conventions and character set to be defined both on a system-wide basis and for individual users or user groups. You set your working environment by assigning the name of the required locale to a set of environment variables reserved for that purpose. Whenever an internationalized program is invoked, these environment variables are read and the information for the locale assigned to them is bound to the program’s runtime environment. Variable affects: LANG Entire locale LC_ALL Entire locale LC_CTYPE Character classes and case conversion (shifting) LC_COLLATE Collating sequence LC_TIME Date and time formats LC_MONETARY Currency symbol and monetary value format LC_NUMERIC Representation of the radix character, exponent character and digit grouping symbol LC_MESSAGES Message texts and answers to yes/no questions The precedence among these variables is as defined in section “Precedence among environment variables” on page 89. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The environment variables which set the locale are: U22794-J-Z125-6-76 87 Defining an internationalized environment International environment (NLS locale) These variables can be defined in one of the following formats: Format 1: variable=locale-name Format 2: variable=language[_territory][.codeset] locale-name language[_territory][.codeset] name of a directory under /usr/lib/locale. The length of this string should not exceed {NL_LANGMAX}. The LC_CTYPE, LC_COLLATE, LC_TIME, LC_MONETARY, LC_NUMERIC and LC_MESSAGES variables also support an additional @modifier element specifying extra alternatives, for example a particular type of collating sequence: LC_variable=language_territory.codeset@modifier Example In a German environment you can use @modifier to choose between the standard collating sequence (dictionary order) and the collating sequence preferred in the German telephone directory. The collation rules here differ in respect of uppercase and lowercase, umlauts and special characters. To select the phone book collating sequence you use the assignment: LC_COLLATE=De_DE.88591@TE If any of the variables LC_CTYPE, LC_COLLATE, LC_TIME, LC_MONETARY, LC_NUMERIC or LC_MESSAGES is undefined or is assigned the null string, its value defaults to the value of LANG. If any of the variables LC_CTYPE, LC_COLLATE, LC_TIME, LC_MONETARY, LC_NUMERIC and LC_MESSAGES has an invalid value, or if the LANG variable is undefined or null, the system acts as if it were not internationalized; in other words, it collates according to the ASCII table, uses the American date format, English day and month names and so on. This is the default setting. 88 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.25 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.k03 International environment (NLS locale) Defining an internationalized environment 3.2.2 Precedence among environment variables Like the LANG variable, the LC_ALL environment variable provides a general announcement mechanism for the entire locale, and it uses the same syntax. Unlike LANG, LC_ALL has the top precedence, which means that it overrides all other international environment variables. Setting LC_ALL is sufficient if one preset locale satisfies all user requirements for program localization. LANG has the lowest precedence; so if it is set, it is still possible to set other international environment variables to customize the working environment of individual users to meet their specific requirements. Precedence Environment variable high LC_ALL medium low LC_CTYPE LC_COLLATE LC_TIME LC_MONETARY LC_NUMERIC LC_MESSAGES LANG Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 A typical case not covered by either LANG or LC_ALL is where you want to communicate with the system in one language but sort text files, for example, in another. In cases of this type, you set the international environment variables which allow you to modify individual aspects (categories) of your locale. Thus if you want to communicate with the system in British English but you also need to sort German text files, you should define the following settings for the LANG and LC_COLLATE environment variables: LANG=En LC_COLLATE=C By setting other variables you can set up a multi-language working environment. i U22794-J-Z125-6-76 Note that the LC_ALL environment variable must be left unset in such cases, as it overrides all other international environment variables. If LC_COLLATE and LC_ALL are both set, LC_COLLATE is ignored. 89 Defining an internationalized environment International environment (NLS locale) 3.2.3 Supplied locales POSIX provides different locales: – C – De – De.EDF04F – De_DE.EDF04 – En_US.EDF04 – De.EDF04F@euro – De_DE.EDF04@EU – POSIX The “POSIX” or “C” locale is equivalent to the behavior defined in the XPG4 standard. The “De” locale is based on the German language, with sorting (collation) based on the standard sort order (as defined by Duden). 3.2.4 Restrictions Commands which are not part of the XPG4 standard (see also page 875) are not internationalized. 90 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc 7. Juli 2009 Stand 11:58.26 4 Commands adduser add individual user number After creating up a new BS2000 user, the POSIX administrator has to assign an individual user number to the new user on systems which do not have SDF-P. The adduser command can only be executed by the POSIX administrator, who must have the group and user number 0. Syntax adduserËuserËuid user User ID for the new users. The user ID must be specified in uppercase letters and corresponds to the BS2000 user ID. It must not be more than 8 bytes long. uid See also chmod, id Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 User number (Ï100) assigned to the new user. The user number must not be the same as the default value (see the BS2000 command SHOW-POSIX-USER-ATTRIBUTES [1]). The user numbers 0 to 99 inclusive are reserved for privileged users. U22794-J-Z125-6-76 91 alias alias Built-in sh command define or display aliases You can use the built-in alias command in the POSIX shell sh to redefine shell commands. However, you may not use it to redefine reserved words. You can use the alias command to define and export alias variables as well as to write them to standard output. The unalias command is used to delete alias variables. Exported alias variables remain effective for procedures which are called by name. However, they must be reinitialized for any new, explicit calls to the POSIX shell. For the use of alias variables see the section “Aliasing” on page 45. Syntax Format 1: alias[Ë-t][Ëname] Format 2: alias[Ë-x][Ëname=[value]]... Format 1 alias[Ë-t][Ëname] No option specified alias with no arguments writes the list of aliases in the form name=value to standard output. -t is used to set and list alias variables which possess a path specification (tracked alias). The value of this type of variable consists of the full path name as far as name. While changing the value of PATH invalidates the value definition, name retains the path specification. If option -t is not set then the pair name=value is output for every name which has no associated value in the argument list. -t not specified: alias outputs the pair name=value for every name which has no associated value in the argument list. Format 2 alias[Ë-x][Ëname=[value]]... A space at the end of value causes the next word in the command line to be checked for alias substitution. -x is used to set and output exported alias variables. An exported alias variable is defined for procedures which are called by name. Exit status The exit status is non-zero if no value is defined for name. Variable PATH Default variable for the POSIX shell. The absolute path name of the directories in which the POSIX shell is intended to search for commands is assigned to the variable. 92 U22794-J-Z125-6-76 Locale 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc Built-in sh command alias The following environment variables affect the execution of alias: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. You can use the following aliases to simplify the ls command: $ alias ll='ls -l' $ alias la='ls -al' unalias Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 93 ar ar archive maintainer ar is used to maintain archives (libraries). In specific terms, you can use ar to perform the following file management functions: Syntax Function Main keys Create an archive file -q or -r Quickly append a file to the end of the archive -q Place/replace a file in the archive -r Delete a file from the archive -d Move a file within the archive -m Print the contents of a file -p List the files in the archive -t Copy (extract) a file from the archive -x Output symbols -S ar[Ë-V]Ëmainkey[modifier]...[posname]Ëafile[Ëfilename]... -V ar prints its version number to standard error output. Main keys When you call ar, you must specify precisely one main key (-d, -m, -p, -q, -r, -t, -x or -S), optionally followed by one or more arguments. -d (d - delete) ar deletes the specified files from the archive. If no files are specified, no action is taken. -m (m - move) ar moves the specified files within the archive. With posname: The files are placed after (a) or before (b or i) the file named posname (see posname). Without posname: The files are appended to the end of the archive. -p (p - print) ar prints the contents of the specified files. If no files are specified, the contents of all files are printed. 94 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc ar -q (q - quickly) ar adds the specified files to the archive "quickly", i.e.: – If the archive already exists, ar appends the named files to it without checking whether they are already present in the archive; – If the archive does not yet exist, it is created. No posname arguments are permitted. The -q option is useful when creating a large archive step by step. -r (r - replace) This option has three different effects, depending on whether the specified archive exists and whether it contains the named files: – If the archive exists and contains the files, ar replaces the named files. – If the archive exists but is missing one or more of the named files, ar adds the missing files to the archive. – If the archive does not exist, ar creates the archive from the named files. With modifier u: ar replaces a file in the archive only if the named file has a later date of last modification than the version already in the archive. With posname: Files not yet in the archive are placed after (a) or before (b or i) the file posfile (see “posname” on page 96). Without posname: Files not yet in the archive are appended to the end of the archive. (t - table) ar prints a table of contents of the archive file. If no files are specified, all files in the archive are listed; otherwise, only the named files. -x (x - extract) ar copies (extracts) files from the archive. If no files are specified, all files in the archive are extracted. The archive itself remains unaltered. -S ((S – Symbols) ar lists all symbols of the specified files. If no files are specified, ar lists all symbols which are contained in the library. The library is not changed by this. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -t U22794-J-Z125-6-76 95 ar Key modifiers c (c - create) The message that ar usually issues when creating an archive is suppressed. C (C - Create) Extracted files are prevented from being overwritten by files of the same name in the file system. This option is useful when -T is also used, to prevent truncated filenames from replacing files with the same prefix in the file system. T (T - truncate) Truncates the names of extracted files. When files are extracted from an archive, their archive names may be longer than the file system can support. By default an error message will be output and the file will not be extracted if the filename is too long. l (l - local ) Can be specified, but is ignored. s (s - symbol table) ar regenerates the archive symbol table, but only if new objects are included in the library or existing objects are replaced. u (u - update) See main key -r. v (v - verbose) ar reports each action it takes (adding files to the archive, moving them within the archive, extracting them from the archive, etc.). If v is used with the -t key, ar displays a detailed listing similar to that produced by the ls -l command (see ls). posname The posname argument specifies the position at which a file is inserted into the archive. posname may be: aËposfile ar inserts the file before the named posfile. bËposfile iËposfile ar inserts the file before the named posfile. posfile is the name of a file already in the archive. afile Name of the archive to be created or processed. file Name of the file to be listed, printed out, added to, extracted from, or moved within the archive. More than one file may be named on the command line. If you specify the same file more than once when calling ar with the -q or -r key, ar will enter the named file into the archive as often as specified. If a number of identically named files are contained in the archive, and you use ar without specifying a position, the first file with the given name will be accessed (rather than the most recent or oldest file, for example). 96 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc ar Structure of an archive 7. Juli 2009 Stand 11:58.26 An archive is a single file that combines several files into one. By convention, the name of an archive file ends with the suffix .a. The purpose of an archive file is to enable the collective maintenance of a group of related files. Archives make it easier to maintain files, since you will often only need to specify the archive file instead of individually listing all its elements. The constituents of an archive are typically object modules that usually form part of the same program or suite of programs. The magic string and the file headers used by ar consist of printable ASCII characters. If an archive is entirely composed of printable files, the entire archive is printable. When ar creates an archive, it creates headers in a format that is portable across all machines. If the archive contains at least one object file, ar creates and maintains an archive symbol table. This symbol table is used by the link editor ld to effect multiple passes over the archive in an efficient manner. The archive symbol table is stored in a specially named file that is always the first file in the archive. This file is never listed or printed out like other archive files and is not accessible to the user. Whenever the ar command is used to create or update the contents of an archive, the symbol table is rebuilt. The symbol table can also be rebuilt by calling ar with the -s option. As far as possible the virtual main memory is used and the export of elements to temporary files is avoided. If this is not successful, temporary files are created, but this is only necessary in the case of the main option –m. The following priorities then apply for the storage location of the temporary files: 1. the current directory Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 2. the directory specified in the TMPDIR variable 3. the /tmp directory Locale The following environment variables affect the execution of ar: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). U22794-J-Z125-6-76 97 ar LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. LC_TIME Determine the format of date and time strings in archive content listings produced in conjunction with the v modifier. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Quickly creating an archive file: $ ar -qv afile.a atoi.o itoa.o ar: creating afile.a a - atoi.o a - itoa.o ar creates the archive afile.a from the files atoi.o and itoa.o. The v modifier tells ar to display the names of the files as they are added. Example 2 Placing a new file at a specified position in an archive: $ ar -rvb atoi.o afile.a atof.o a - atof.o ar copies atof.o into the archive file afile.a, placing it before atoi.o. Example 3 Printing the table of contents of an archive: $ ar -tv afile.a rw-r--r-- 104/ rw-r--r-- 104/ rw-r--r-- 104/ 1 1 1 2276 Jul 13 12:17 2008 atof.o 759 Jul 13 12:17 2008 atoi.o 1280 Jul 13 12:17 2008 itoa.o Example 4 Extracting (copying) a file from an archive: $ ar -xv afile.a atoi.o x - atoi.o The file atoi.o is copied from the archive afile.a into the working directory. The copy is also called atoi.o. See also 98 cpio, pax, tar U22794-J-Z125-6-76 asa interpret carriage-control characters asa will write its input files to standard output, mapping carriage-control characters from the text files to line-printer control sequences.The first character of every line will be removed from the input, and the following actions will be performed: If the character removed is: 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc asa space The rest of the line will be output without change. Syntax 0 A newline character will be output, then the rest of the input line. 1 One or more characters that causes an advance to the next page will be output, followed by the rest of the input line. + The newline character of the previous line will be replaced with one or more characters that causes printing to return to column position1, followed by the rest of the input line. If the + is the first character in the input, it will have the same effect as the space character. asa[Ëfile ...] file A pathname of a text file used for input. If no file operands are specified, the standard input will be used. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of asa: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH See also Determine the location of message catalogs for the processing of LC_MESSAGES. lp U22794-J-Z125-6-76 99 at at execute commands at a later time The at command – reads commands from standard input or from a shell script and executes them at a later time specified by the user. A command list created in this way runs under a job number. (Format 1 and 2) – lists on standard output any jobs scheduled with at or batch (see batch) which have not yet been processed (Format 3 and 4) – removes jobs previously scheduled with at or batch (Format 5). The output from Format 1 and Format 2 is sent to the user by mailx unless the standard output and standard error output of the commands to be executed have been redirected. The environment variables, the current directory, the permissions for new files (see page 778) and the maximum permissible file size (see page 775) are retained, but open files and priorities are lost, and the trap command (shell built-in for catching signals) is deactivated. at writes the job number and the schedule time to standard error. Jobs scheduled with at are retained even if the user who scheduled them closes the POSIX shell with exit or if the POSIX subsystem is shut down. There is no need to reschedule the jobs. Before the call The user ID must have a standard account number for rlogin access. This standard account number can be assigned using the ADD-USER, MODIFY-USER-ATTRIBUTES or ADDPOSIX-USER command. If the file /usr/lib/cron.d/at.allow exists, you can only use at if your login name appears in it. If the file /usr/lib/cron.d/at.allow does not exist, you can only use at if your login name does not appear in the file /usr/lib/cron.d/at.deny. If neither /usr/lib/cron.d/at.allow nor /usr/lib/cron.d/at.deny exists, only the POSIX administrator is allowed to use at. If only an empty deny file exists, for example, everyone is allowed to use at. Only the POSIX administrator is allowed to create and modify the allow/deny files. Each line in these files contains precisely one login name. The cron daemon is started by means of an rc script. 100 U22794-J-Z125-6-76 Syntax Format 1: at[Ë-m][Ë-fËscript][Ë-qËqueue]Ë-tËtime Format 2: at[Ë-m][Ë-fËscript][Ë-qËqueue]Ë time Format 3: atË-l[Ëjobnumber] Format 4: atË-lË-qËqueue 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc at Format 5: atË-rËjobnumber Execute commands at a later time Format 1 at[Ë-m][Ë-fËscript][Ë-qËqueue]Ë-tËtime -fËscript at reads the commands to be executed from the specified shell script. You can specify a number of commands, separated from one another by a semicolon (;) or a newline character. A command list created in this way runs under a job number. You can exit the command list terminal-dependent with @@d or [END]. -f not specified: at reads the commands to be executed from the standard input. -m Sends mail to the user after a job has been completed, indicating that the job is finished. Mail is sent only if the job has not already generated a mail message. -qËqueue The -q option is used to assign a job to a specific queue in the /var/spool/cron directory. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The values accepted for queue are: a for the default queue for jobs scheduled with at. b for the default queue for jobs scheduled with batch. c for the default queue for jobs scheduled with crontab. -tËtime Specifies the execution time for the commands. time is specified as follows: [[CC]YY]MMDDhhmm[.SS] CC The first two digits of a date (century). CC not specified: If the two-digit date is greater than 68, the current century is assumed, otherwise the following is used. YY Two-digit year specification. YY not specified: The current year is assumed. MM Two-digit month specification (01 bis 12) U22794-J-Z125-6-76 101 at Format 2 DD Two-digit day specification (01 bis 31) hh Two-digit hour specification (00 bis 23) mm Two-digit minute specification (00 bis 59) SS Two-digit second specification (00 bis 61) The values 60 and 61 are intended for leap seconds. SS not specified: The value 0 seconds is assumed. at[Ë-m][Ë-fËscript][Ë-qËqueue]Ëtime The options are described under Format 1. time Specifies the execution time for the commands. time is specified as follows: time[Ëdate][Ë+increment] time digits[suffix] or special_name digits: [h]h 1- and 2-digit numbers are interpreted as hours. hhmm 4-digit numbers are interpreted as hours and minutes. [h]h:[m]m Digits separated by a colon are interpreted as hours and minutes. suffix: am Interpreted as before 12 noon (dependent from the locale LC_TIME) pm Interpreted as after 12 noon (dependent from the locale LC_TIME) am, pm omitted Interpreted as 24-hour clock zulu[am][pm] special_name: date Interpreted as Greenwich Mean Time noon, midnight, now monthËday[,year] or weekday[Ënextweek|nextËweek] or special_day month (dependent from the locale LC_TIME): jan[uary], feb[uary], mar[ch], apr[il], may, jun[e], jul[y], aug[ust], sep[tember], oct[ober], nov[ember], dec[ember], nextmonth | nextËmonth day 102 A number between 1 and 31, depending on how long the month is. U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc at year Number defining the year to which the date applies nextyear | nextËyear: selects the following year year not specified: If the date given is after the current date, at assumes the next year; otherwise, the current year. 7. Juli 2009 Stand 11:58.26 weekday (dependent from the locale LC_TIME): mon[day], tue[sday], wed[nesday], thu[rsday], fri[day], sat[urday], sun[day] nextweek|nextËweek: selects the following week special_day: today, tomorrow, nextday, nextËday nextday (or nextËday) means that the job is executed a full day later. If the specified time lies before the current time, at interprets the following day as the current day. For example, if the job at 10 nextday were scheduled at 11:00am on 7/1/95, the job would be executed at 10:00am on 7/3/95; however, if at 14 nextday were specified at the same time, execution would begin at 14:00 hours on 7/2/95. date not specified: – corresponds to today if the specified time (rounded to the nearest minute) lies after the current time – corresponds to tomorrow if the specified time (rounded to the nearest minute) lies after the current time – corresponds to now if the specified time (rounded to the nearest minute) lies after the current time Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 +increment increment is a positive integer that must be followed by one of the following units of time: minute[s], hour[s], day[s], week[s], month[s], year[s] Examples at can typically be specified in the following ways: at at at at U22794-J-Z125-6-76 0815am jan 24 8:15am jan 24 5pm friday now +1hour 103 at List jobs yet processed Format 3 atË-l[Ëjobnumber] Format 4 atË-lË-qËqueue -l[Ëjobnumber] at lists the specified jobnumber, if the corresponding job has not yet been processed. jobnumber is the number that is reported on standard error when a job is scheduled with at, batch or cron. jobnumber not specified: at lists all jobs that are yet to be processed, together with their job numbers. -lË-qËqueue It is possible to specify the queue as an alternative to the jobnumber. at lists all of the jobs in queue. Remove jobs Format 5 atË-rËjobnumber -rËjobnumber at removes the job jobnumber, which was previously scheduled with at or batch. jobnumber is the number reported on standard error when a command job is scheduled with at or batch. You can specify more than one job number, using blanks to separate them. Only the POSIX administrator is authorized to remove another user's jobs. Exit status 0: at executed successfully ≠0: An error occurred while at was executing Error The commonest error messages are: at: bad date specification You have entered the date in an incorrect format. at: too late The date you specified has already passed. at: This job may not be executed at the proper time time lies between "now" and "now+1hour". at: you are not authorized to use at. Sorry. You are not authorized to use at. Sorry. (See Before the call) 104 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc at File /usr/lib/cron/at.allow List of login names with permission to use at. One login name is entered per line. /usr/lib/cron/at.deny List of login names explicitly denied permission to use at. One login name is entered per line /var/spool/cron/atjobs Directory containing a separate file for each at job which has not yet been executed. Each at job is allocated a file of its own with the file name jobnumber.a. Variable SHELL Determine a name of a command interpreter to be used to invoke the at job. If the variable is unset or null, sh will be used. If it is set to a value other than a name for sh, the implementation will do one of the following: use that shell; use sh; use the login shell from the user database. TZ Determine the timezone. The job will be submitted for execution at the time specified be timespec or -t time relative to the timezone specified by the TZ variable. If timespec specifies a timezone, it will override TZ. If timespec does not specify a timezone and TZ is unset or null, an unspecified default timezone will be used. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of at: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. LC_TIME Determine the format of date and time string. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 105 at Example The current date and the string April Fool! are to be displayed on terminal tty013 at 9 o’clock in the morning on the 1st of April. $ at 1pm apr 1 Ú echo `date`":April Fool!" >> /dev/tty013 Ú [END] or @@d See also 106 batch, crontab, date, kill, mailx, nice, ps, sh, sort U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk awk pattern scanning and processing language awk is a programmable text manipulation system. When you call awk you specify an awk program it is to execute and the files it is to process. The actions defined in the program are then performed on the basis of the specified files. awk does not alter its input files. The results of the actions it performs are by default written on standard output. awk offers the following advantages over text manipulation programs such as egrep and sed: ● awk operates on one record at a time. As with egrep and sed, an input record is defined as one line by default; but with awk you can change this setting and define some other unit of text as the record. ● Each input record is split into fields which can be accessed individually. ● A pattern (selection criterion) may be a condition defined by the logical combination of extended regular expressions and relational operators. ● You can program any actions that you require. awk is a high-level C-like programming language. ● Typical awk applications (see page 110) ● Structure of an awk program (see page 112) ● Operation of the awk command (see page 113) ● The input file (records, fields, special variables) (see page 113) ● Basic elements of the awk language (comments, constants, variables) (see page 117) ● Expressions (see page 122) ● Patterns (see page 124) ● Actions (control-flow statements, functions) (see page 126). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 A detailed description of awk is provided below in the following sections: U22794-J-Z125-6-76 107 awk Syntax Format 1: awk[Ë-FËERE][Ë-vËinitialization]...Ëprog[Ëinitialization]...[Ëfile]... Format 2: awk[Ë-FËERE][Ë-fËprogfile]Ë[ËvËinitialization]...[Ëinitialization]...[Ëfile] -FËERE Defines the field separator character for the input record (input field separator). ERE Extended regular expression that defines a character to be interpreted as the input field separator. Separators do not form part of the fields. i To be able to use t as the input field separator, you must specify it as follows on the awk command line or in the BEGIN section of the awk program: awk -F“[t]“... or BEGIN {FS=“t“...} -FËERE not specified: Blanks and tabs act as field separators. -vËinitialization Assignments in the form var=value. The var variable which appears in the program is initialized to value. var Name of the variable to be initialized. value Initial value to be assigned to var. value can be defined in exactly the same way as an environment variable on shell level. There is no difference between the assignment of a value with -v initialization and with initialization (see below). prog awk program argument. Possible forms for prog are: – ’awk-program’, i.e. an awk program written on the command line, or – -f progfile, i.e. the name of a file containing an awk program. ’awk_program’ An awk program written on the command line. You should always enclose the awk program in single quotes in order to prevent the shell from interpreting metacharacters. If the program is more than one line long, you must escape the newline character with a backslash. Example: Output all lines in the input file whose third field consists of the character ’0’ $ awk '$3 == 0' input 108 U22794-J-Z125-6-76 -fËprogfile The awk program is located in the file named progfile. initialization Assignments in the form: var=value The var variable (whether it appears in the awk program or not) is initialized to value. initialization and file may be specified in any order. The assignment is made at the time when the named file is opened. Thus, an assignment before the first file argument will be executed after the BEGIN actions (if any), while an assignment after the last file argument will occur before the END actions (if any). 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk Exception The $ variables (see Basic elements) cannot be initialized in this way. var Name of the variable to be initialized. The name must not begin with $. value Initial value to be assigned to var. value can be defined in exactly the same way as an environment variable on shell level. file Name of the text file to be processed. You may list more than one file if you wish. Files are read in the order in which they are listed. If file is a dash (-), awk reads from standard input. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file not specified: awk reads from standard input. awk reads input one record at a time, processes it, and after each line outputs the result for that record. Hitting [END] or [CTRL][D] or @@d terminates your input. U22794-J-Z125-6-76 109 awk, Typical applications Typical awk applications awk is a tool which makes text manipulation tasks easy to accomplish. Typical applications for awk include: – selectively extracting data from files – checking the contents of files – performing calculations on the data in a file – changing the format of input data. Using four simple examples, this section demonstrates how awk can be used. Example A file called supplies contains a list of office supplies. It includes the name of each article, along with its quantity and unit price: Pencil Table Lamp Paper Diskette Envelope 100 5 20 75 1000 1500 0.60 345.00 79.80 1.00 2.40 0.20 Example 1 Select all articles with a quantity greater than 100: $ awk '$2 > 100 {print}' supplies Diskette 1000 2.40 Envelope 1500 0.20 With $2 you access the second field of a line, which in this case is the quantity of each article. If the quantity is greater than 100, the condition is fulfilled, and the print function is executed. Since no arguments were specified for print, the whole line is output. Example 2 Calculate the total price for all articles with a quantity greater than 100 and print this total along with the article name: $ awk '$2 > 100 {print $1 "\t" $2*$3}' supplies Diskette 2400 Envelope 300 Three arguments are entered for the print function in this example. The following is output: $1 article name (first field) \t tab character $2*$3 quantity (second field) times unit price (third field) 110 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Typical applications Example 3 Include a heading in the output: $ awk 'BEGIN > $2 > 100 Article Diskette Envelope {print "Article \tTotal"} {print $1 "\t" $2*$3}' supplies Total 2400 300 This example illustrates the use of the BEGIN pattern. awk executes the action after BEGIN only once, i.e. when the program is started. The heading is therefore printed only once at the beginning. Example 4 Print a grand total of all amounts at the end. For this purpose we use a variable called sum, which is initialized to zero in the BEGIN pattern. The product of column 2 and column 3 is calculated for each line, and all the products are summed up: $ awk 'BEGIN {sum=0; print "Article \tTotal"} > $2 > 100 {print $1 "\t" $2*$3; sum += $2*$3} > END {print "\nGrand total: " sum} ' supplies Article Total Diskette 2400 Envelope 300 Grand total: 2700 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 This example demonstrates the use of the END pattern. awk executes the action after END only once, i.e. before termination of the program. The grand total of all subtotals is therefore printed just once at the end. U22794-J-Z125-6-76 111 awk, Program structure Structure of an awk program An awk program can consist of a BEGIN section, a main section, and an END section, structured as shown below: Syntax [ BEGIN {action} ] [[pattern] {action} | pattern [{action}] | function_definition . . . BEGIN section main section ] [ END {action} ] END section pattern The pattern indicates which data is to be selected from the input files (see page 124). action The action indicates what to do with data that matches the pattern (see page 126). function-definition A function_definition enables you to define your own functions (see page 133). At least one of the three sections (pattern, action or function-definition) must be present. In a pattern {action} pair, either the pattern or the action can be omitted. If the action is omitted, each line that matches the pattern is output; omitting the pattern causes the action to be performed on all lines. The definition of a user-defined function may appear at any position in the main section. Each of the following ust be located at the start of a line (following any number of blanks or tabs): – – – – 112 the BEGIN section the [pattern]{action} and pattern [{action}] pairs the function definitions the END section. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Operation Operation of the awk command awk executes the awk program that is specified by the user, proceeding in the following sequence: 1. Initial processing The first step performed by awk is to initialize any variables that may have been defined. If there is a BEGIN section including an action, awk then executes the action specified there. The action in the BEGIN section is executed just once, before the first line is processed. 2. File processing Next awk processes the specified input files by reading the input records sequentially. For each input record, awk tries to match each pattern in the order that is specified in the awk program. If a pattern is matched, i.e. the selection criterion is fulfilled, the associated action is performed. If no pattern is specified for an action, awk performs the action for every record. If no action is specified for a pattern, the default action is to output (print) the record. Multiple input files are processed in the specified order. 3. Final processing When all the specified files have been processed, awk performs the action in the END section, if one has been included. awk then exits. The input file An input file consists of records that are subdivided into fields. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 – Records Records are separated by a record separator. The record separator does not form part of a record. By default, a record is one line, and the record separator is the newline character. However, you do have the option of changing this setup by assigning any single character to the special variable RS (Record Separator). If you specify a string of characters as a value for RS, only the first character will be taken into account. The ordinal number of the current record is available in the variable NR (Number of Record). If there is more than one input file, NR counts from the start of the first file to the end of the last one. The special variable $0 addresses the whole of the current record. Further information on variables is provided in the section “Basic elements of the awk language” on page 117. U22794-J-Z125-6-76 113 awk, Input file – Fields Each record is split into fields separated by one or more field separators. The default field separator is white space (any sequence of tabs and blanks), but you do have the option of changing this by assigning any other character to the special variable FS (Field Separator). You can make this assignment either in the awk program or by using option -F on the command line. The value assigned to FS is interpreted as an extended regular expression (see section “Regular POSIX shell expressions” on page 877). Example 1 To define the characters x and y as alternate field separators: syntax on the awk command line: -F[xy] syntax in the awk program: FS=[xy] Example 2 To define the field separator as one or more occurrences of the character x: syntax on the awk command line: -Fx+ syntax in the awk program: FS=x+ The default setting (any sequence of blanks and tabs) can be expressed by the regular expression [Ë\t]+, where stands for a blank, and \t represents a tab. Note that the newline character is always interpreted as a field separator, regardless of the value assigned to FS! The number of fields in the current record is stored in the variable NF (Number of Fields). Individual fields of the current record are addressed by the predefined variables $1, $2, to $NF. Further information on variables is provided in the section “Basic elements of the awk language” on page 117. Example Default setup Field 1 Field 2 ... Field 5 ... This is the first record <--- Record 1 and this is the second record. <--- Record 2 Customized setup: RS="%"; FS=":"; Field 1 %Name Field 2 : Address Field 3 : Phone number %SNI AG :81730 Munich : 089-636-1 114 <--- Record 1 <--- Record 2 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Input file Rules for record and field separators ● Default settings for record separators – The default record separator is the newline character. – If the null string is assigned to RS (RS=""), the file is treated as a single record. If several files are specified, each file will consist of a single record (which means that the ultimate value of NR will be equal to the number of files). ● Default settings for field separators – If the record separator is newline, the field separator defaults to blanks and tabs. – If the record separator is not a newline, the newline character always counts as a field separator, regardless of which character has been explicitly defined as the field separator (see example 2 on page 114). – If you explicitly assign a blank to FS, either with -F" " on the awk command line or by using the assignment FS=" ", then blanks and tab characters are treated as field separators. – On the other hand, if you explicitly assign the tab character to FS (FS="\t"), then only the tab character is treated as the field separator and not the blank. ● Leading field separators and field separator strings – The following applies to blanks, tabs and newlines as field separators: – Leading field separators are ignored. – Multiple occurrences of a field separator are treated as a single field separator (see example 9 on page 147). – For all other field separators, leading field separators are counted. In multiple occurrences of a field separator, each character is counted separately. Thus two consecutive field separators are deemed to have an empty field between them (see example 10 on page 148). ● Changing separators: If you need a number of different record separators in one file, you can change RS within the awk program. The new record separator comes into effect as soon as the assignment to RS has been implemented. Similarly, you can change FS within the awk program, should you require a number of different field separators in one file. The new field separator comes into effect as soon as the assignment to FS has been implemented. U22794-J-Z125-6-76 115 awk, Input file Special variables for the input file The following table contains all special awk variables pertaining to the input file. The value awk usually assigns to these variables is indicated in the second column. Variable Value set by awk FILENAME Name of the current input file, - for standard input FS Input field separator (default: any sequence of blanks and tabs) NF Number of fields in the current record NR Ordinal number of the current record from start of input FNR Ordinal number of the current record in the current file RS Input record separator (default: newline) $0 $1 $2 ... $NF Current record First field of the current record Second field of the current record Last field of the current record You can change these variables within an awk program if you wish. This does not alter the input file. Further information on variables is provided in the section “Basic elements of the awk language” on page 117. 116 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Basic language elements Basic elements of the awk language This section gives a syntax of the basic elements of the awk language. You will need these elements in order to define pattern and action pairs. Comments You can include comments in an awk program, as in a shell script. A comment begins with the # character and continues till the end of the line. Constants There are two types of constant: number A number (numeric constant) is a signed or unsigned integer or floating point number. awk does not check its format. If your number contains invalid characters, awk attempts to filter out a valid part and ignores the rest. integer An integer is a sequence of digits from 0 to 9. floating point number A floating point number consists of a mantissa with or without an exponent. The mantissa comprises an integer with or without a fractional part. The fractional part is represented by a radix character and an integer. character A single character is also enclosed in double quotes "..." in order to prevent awk interpreting the character as a variable name. A character may be a displayable character from the character set which is currently in use (see section “EDF04 character set” on page 893) or one of the following special characters as represented in C: \" \\ \a \n \t \v \b \r \f Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 string A string (alphanumeric constant) is a sequence of characters, enclosed in double quotes "...". If the double quotes are omitted, awk will interpret the string as a variable name, a number, or an operator. U22794-J-Z125-6-76 for for for for for for for for for " \ bell character newline character tab character vertical tab backspace carriage return page feed 117 awk, Basic language elements Variables awk allows you to use simple variables and arrays to store values. The special variables are predefined; others can be defined by the user. Name of a variable The name of a user-defined variable can be any string made up of underscores (_), uppercase and lowercase letters and digits, beginning with a letter or an underscore. Data type Variables do not have a data type. You can thus assign either a number or a string to any variable. If the context is clearly numeric, variables are treated as numeric; otherwise, they default to alphanumeric. Example: x = "Miller"; x = "3"+4 ; # Variable x contains the string Miller # Variable x has a value of 7 Declaration awk variables do not need to be explicitly declared. User-defined variables are automatically declared the first time they are used. Initialization Special variables are initialized to predefined values by awk. Depending on the context, user-defined variables are initialized by awk to the null string or to 0 by default. If you wish, you can specify other initial values when you call awk. Exceptions: – When i>NF, $i will not always be the null string. – $ variables cannot be initialized on the command line. 118 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Basic language elements Special variables awk recognizes the special variables listed in the table below. The values awk usually assigns to these variables are indicated in the table. New values may be assigned to the variables by the user. Variable Value set by awk ARGC Number of elements in the array ARGV ARGV Array holding the command line arguments (excluding options and the prog argument), numbered from 0 to ARGC-1 ENVIRON Array holding the values of environment variables, where the indexes are the names of the variables FILENAME Name of the current input file, - for standard input FS Input field separator (default: any sequence of blanks and tabs) NF Number of fields in the current record NR Ordinal number of the current record from start of input FNR Ordinal number of the current record in the current file OFS Output field separator (default: one blank) ORS Output record separator (default: newline) OFMT Output format for floating point numbers (see page 140) (default: %.6g, up to 6 places after the decimal point) RS Input record separator (default: newline) RLENGTH Length of the string matched by the match function RSTART Starting position of the string matched by the match function. Numbering begins with 1.This value always corresponds to the value returned by the match function. SUBSEP Subscript string separator for multi-dimensional arrays. The default setting is \034. $0 Current record $n Field n of the current record $NF Last field of the current record U22794-J-Z125-6-76 119 awk, Basic language elements What is the effect of changing special variables? Example The assignment $1 = "new"; assigns the string new to $1; but this does not actually alter the first field of the current input record. This also applies to the following awk settings relating to the input file: 1. The current input file does not change when you assign a new name to FILENAME. 2. When you assign a value to a variable $i where i>NF, NF is assigned the value i. 3. If you assign a new value to NR, you only alter the number assigned to the current line; you do not move to a different line. Example The contents of $0 remain the same even if NR is modified: {print NR, $0; NR=NR+34; print NR, $0} A typical output would then be: 10 This is the tenth line 44 This is the tenth line i When you assign a new value to a variable, its old value is deleted. Thus, if you change NF, for example, the information on the number of fields in the current record is lost. Peculiarity of $ variables: You can specify the number of a $ variable as a constant or as an expression which evaluates to the number. Example 120 You can use $(NF-1) to access the second-last field. U22794-J-Z125-6-76 Array An array is a set of constants or variables. An array element is addressed as follows: Syntax array_name[index] array_name Name of a variable. 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Basic language elements index A simple variable. The index may be numeric or alphanumeric. The index you specify can therefore be a number, a string, or an expression that evaluates to an index value. awk provides two special types of arrays: ● Dynamic arrays Arrays, like simple variables, do not need to be declared. Above all, there is no need to define dimensions. New array elements are created automatically as and when required. ● Associative arrays Individual array elements can be accessed via an alphanumeric index. A special control-flow statement is provided in order to process all elements of an associative array: for (index in array) statement index assumes the index values present to this point in random order, and the specified statement is executed once for each array element (see control-flow statement for). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example A file called expenses contains various expenses incurred. For each item of expenditure the file shows the date, month, amount, and a brief description, with a colon to separate them. For example: 01:January: 40.78:Supplies 05:January: 6789.00:Laser printer 23:March: 240.32:Lamps 11:January: 478.00:Chairs 01:February: 45.00:Journals Using an associative array you can easily calculate total expenditure for each month from the data in this file. The program in the example uses an array called mexpenses and the names of the months as an alphanumeric index. For each line, the expenses in the third field ($3) are summed up to produce total expenditure for each month appearing in the second field ($2). U22794-J-Z125-6-76 121 awk, Expressions $ awk > > > Total Total Total 'BEGIN {FS=":"} {mexpenses[$2] += $3;} END {for (i in mexpenses) print "Total spent in",\ i, mexpenses[i] } ' expenses spent in January 7307.78 spent in February 45 spent in March 240.32 Expressions An expression can be any of the following: Syntax – – – – – – – constant variable function_call un_op expression expression bin_op expression (expression) expression ? expression : expression constant Numeric or alphanumeric constant (see “Basic elements of the awk language” on page 117. variable Variable (see “Basic elements of the awk language” on page 117). function_call Invocation of a predefined function (see page 133). expression Expression. un_op Unary operator (see “awk operators” on page 123). bin_op Binary operator (see “awk operators” on page 123). Expressions are evaluated and return a value. They may appear both in patterns and in actions. 122 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Expressions awk operators awk recognizes all C operators plus the operators for pattern matching and string concatenation. The following table lists all awk operators in ascending order of precedence. Operators in the same line have the same precedence Operator Meaning = assignment operator += -= *= /= %= ^= compound assignment operators as in C || logical OR && logical AND ~ pattern matching operators !~ > >= < <= != == relational operators operand list concatenation + - plus, minus * / % multiply, divide, remainder ! logical NOT ^ ** exponent ++ -- increment, decrement Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Evaluation of expressions Since no data type is prescribed for the operands, you can freely mix numeric and alphanumeric constants. awk determines from the context whether a numeric or alphanumeric operation is required. Please note that, as in C, there are no special truth values. Like C, awk treats a value of 0 as false and a non-zero value as true. This means that any non-zero value as an argument of a logical operation is held to be true. If the result of a logical operation is true, it is represented as 1. Example (2&&2)+3=4 U22794-J-Z125-6-76 123 awk, Patterns Patterns Patterns (selection criteria) are specified by the user as a means of indicating which data is to be selected from the input files. A pattern can have any of the following forms: Syntax – – – – – /regexp/ relexp matchexp pattern_range compound_pattern /regexp/ - Regular expression awk supports extended regular expressions (see section “Regular POSIX shell expressions” on page 877). A regular expression is enclosed in slashes /.../. Example A regular expression matching any number of occurrences of a, b or c: /[abc]+/ compare relexp relexp is an expression (see page 122) featuring relational operators. The operators and their meanings are: a>b a greater than b? a >= b a greater than or equal to b? a= "M" && $1 < "Q" U22794-J-Z125-6-76 125 awk, Actions You can generally combine patterns in several ways in order to make the same selection. Thus, if the currently valid collating sequence defines the range [M-Q] as the uppercase letters M, N, O, P and Q, the above selection could also be made with pattern matching operators: NF%2==0 && $1 ~ /^[MNOP]/ Since the first awk condition depends on t he collating sequence of the currently valid character set, it may not return the same result in every case. The second awk line, by contrast, will always select only those records in which the first field begins with the letter M, N, O or P. Actions Actions indicate what to do when a pattern is matched. An action will typically involve processing one of the selected files. An action has to begin in the same line as the associated pattern. If this is not possible, the newline character must be escaped with a backslash. Blanks and tabs between the action and the pattern are ignored. An action comprises one or more statements and must be enclosed in braces {...} as shown below: Syntax {statementË[;statement]...} Statements A statement can be any of the following: Syntax – – expression control_statement expression An expression is evaluated but is not put to any further use unless expression is in the form of an assignment, an increment or a decrement (see section “Expressions” on page 122). control_statement A control_statement allows you to control the flow of an awk program (see section “Control-flow statements” on page 127). A single statement may be spread over several lines, in which case each line except the last must end with a backslash. The backslash escapes (cancels the effect of) the newline character. Multiple statements You can group together a number of statements within one pair of braces {}. Statements are delimited by means of: – a semicolon ; – a right brace } – a newline character. 126 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Control-flow statements Control-flow statements 7. Juli 2009 Stand 11:58.26 Control-flow statements allow you to control the flow of an awk program. awk recognizes the following control-flow statements: Statement Meaning break terminate a loop continue skip remainder of loop exit terminate the awk program for loop counter and looping an array if conditional statement next skip to the next input record while execute iteratively do execute iteratively delete array[i] delete element i of the named array return x return from a function with a value return return from a function without a value The control-flow statements are described below in alphabetical order. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 break - Terminate a loop break can be used in the body of a for, while, or do loop. break causes an immediate exit from the enclosing loop. Syntax break Example While records continue to start with a dot, keep reading in the next record. Terminate the loop if the second field of the retrieved record is greater than 1000. { while($1 ~ /^\./) { getline; if($2 > 1000) break; } } U22794-J-Z125-6-76 127 awk, Control-flow statements continue - Skip remainder of loop continue can be used in the body of a for, while or do loop. The continue statement causes the current iteration to be terminated and the next one to begin. Syntax continue Example Print even fields only: { i=1; while(i++ <= NF) { if(i%2) continue; else print $i } } do - Execute iteratively The statement in a do loop (or a do-while loop) is executed iteratively while a specified condition continues to be satisfied. In contrast to the while loop, the statement in a do loop is always executed at least once. Syntax doË{anweisung}ËwhileË(expression) statement Statement that is executed in each iteration of the loop. If several statements are to be executed, they have to be grouped together in braces ({ }) and separated by semicolons or linefeed characters. expression Expression (see page 122) that specifies the condition. Example Print out the individual fields of a record: { i=0; do {print $(++i)} while (i != NF) } 128 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Control-flow statements exit - Terminate the awk program exit terminates the awk program. If an END section is present, awk executes the action specified in it; if not, the program is terminated immediately. Syntax exit Example If the commercial at symbol @ appears in the input, print the result and terminate processing: ... /@/ {exit} ... END {print ergebnis} for - Loop counter The statement in a for loop is executed iteratively while a condition continues to be satisfied. Syntax for(expr1; expr2; expr3) statement expr1 Expression (see page 122). expr1 is evaluated once at the start of the for statement. expr1 is often used to initialize incrementing variables. Example:i=1 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 expr2 Expression (see page 122). expr2 is evaluated before each iteration. The specified statement is executed only if expr2 is non-zero (true); otherwise, the loop is terminated. Example:i<10 expr3 Expression (see page 122). expr3 is evaluated after each iteration. When incrementing variables are used, expr3 increments the variable. Example:i++ statement Statement that is executed in each iteration of the loop. If several statements are to be executed, they have to be grouped together in braces {}. Example Print out the fields of the current record in reverse order. {for(i=NF; i>0; i--) print $i} U22794-J-Z125-6-76 129 awk, Control-flow statements for - Looping an array This variant of the for statement is a special awk facility for the handling of arrays. Syntax for(indexËinËarray)Ëstatement index Variable (see Basic elements) that assumes all values of the elements of array in random order. The index can be numeric or alphanumeric. array Array to be processed. statement Statement to be executed for each array element. If several statements are to be executed, they have to be grouped together in braces { }. Example The array named month contains the number of days in each month. Each array element is subscripted with the name of the month, e.g. month["January"]=31. The following awk program prints the name of each month together with the number of days in it. $ awk ' BEGIN { month["January"]=31; \ > month["February"]=28; \ > month["March"]=31; \ > month["April"]=30; \ > month["May"]=31; \ > month["June"]=30; \ > month["July"]=31; \ > month["August"]=31 } \ > END { for(i in month) print i,"has",month[i],"days" } ' May has 31 days August has 31 days July has 31 days April has 30 days June has 30 days January has 31 days March has 31 days February has 28 days 130 U22794-J-Z125-6-76 if - Conditional statement The statement in an if construct is executed if the specified condition is satisfied. Syntax if(expr)Ëstatement1Ë[elseËstatement2] expr Expression (see page 122) that defines the condition to be satisfied. If expr is non-zero (true), statement1 is executed. 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Control-flow statements statement1 Statement to be executed if expr is true. If several statements are to be executed, they have to be grouped together in braces { }. statement2 Statement to be executed if expr is false. If several statements are to be executed, they have to be grouped together in braces { }. Example If field 1 is greater than field 2, fields 2 and 3 are printed; if not, fields 4 and 5 are printed: { if($1 > 2) print $2, $3; else print $4, $5 } next - Skip to the next input record The next statement causes awk to suspend processing of the current record; statements that follow next are not applied to the current record. awk then reads the next input record. NR, NF, FNR, $0, and $1 to $NF are reset. Difference between next and the getline function: Syntax next Example Records that begin with a dot are ignored: { if ($1 ~/^\./) next } Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 getline sets the current record to the next one. Statements that follow getline are executed using the next record’s values for the $ variables and for NR, NF, and FNR. U22794-J-Z125-6-76 131 awk, Control-flow statements while - Execute iteratively The statement in a while loop is executed iteratively while a specified condition continues to be satisfied. Syntax while(expr)Ëstatement expr Expression (see page 122) that specifies the condition. statement Statement that is executed in each iteration of the loop. If several statements are to be executed, they have to be grouped together in braces { }. Example Print all input fields, writing each field in a separate output line: { i = 1; while (i <= NF) { print $i i++ } } 132 U22794-J-Z125-6-76 Functions awk provides a wide range of built-in functions and also offers you the option of defining functions of your own: Syntax functionËname(arg,...)Ë{statements} The {statements} may be preceded by a newline character. There may also be blank lines within the braces {...}. A function definition has the same precedence as pattern {action} pairs in the main section of an awk program. 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Functions Within an action section, function calls can be entered anywhere in an expression, except before the function declaration. There must be no space between the function name and the left parenthesis when a function is called. Nested and recursive function calls are legal. Though most functions do not require you to enclose arguments in parentheses, it is a good practice to use them as a means of increasing program transparency. When you pass an array as an argument, a pointer to the array is passed (call by reference), which means that you can change the elements of the array from the function. In the case of scalar variables, the value of the variable is copied and passed (call by value), which means that you cannot change the value of the variable from the function. The scope of function arguments is restricted to the local function, whereas the scope of all other variables is always global. If you need a local variable in a function, define it at the end of the argument list in the function definition. Any variable in the argument list for which no current argument exists is a local variable with a predefined value of 0. Example In the example below, the function named search looks for the string who in the array allnames and returns the index or -1. The third argument, incr, is used as a local variable. ... { print $1, search($1, allnames) } ... function search(who, allnames, incr) { for (incr=0; allnames[incr]; incr++) if (index(allnames[incr], who) == 1 && length(allnames[incr]) == length(who)) return incr return -1 } Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 As in C, some functions return a result (e.g. exp), while others are procedural in character (e.g. output functions). The return statement can be used with or without a return value or may be omitted entirely. In the latter case, the return value would be undefined if it were to be accessed. U22794-J-Z125-6-76 133 awk, Functions Built-in functions Function Purpose Input function getline Read input record Output functions print([arg,...]) Standard output function printf(format [arg,...]) Formatted output Arithmetic functions atan2(y,x) Arc tangent of y/x cos(x) Cosine exp(x) Exponential function int(x) Truncate to integer log(x) Natural logarithm rand() Return a random number sin(x) Sine sqrt(x) Square root srand([x]) Set the seed (initial value) for rand() String functions gsub(re,repl[,instr]) Global substitution function index(str1,str2) Return first occurrence of substring length([str]) Return length of string match(str,re) Check whether string str matches regular expression split(str,array,[sep]) Subdivide string sprintf(format,e1,e2,...) Return formatted output as string sub(re, repl[,instr]) Substitution function substr(str,m,[n]) Define substring tolower(s) Convert to lowercase toupper(s) Convert to uppercase General functions 134 close(expr) Close file or pipe system(expr) Call shell command U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Functions The following section describes each of these functions in alphabetical order together with the associated arguments. The argument you specify can either be a constant or an expression (see page 122). awk first evaluates the expression arguments and then applies the function to the computed results. atan2 - Arc tangent atan2 calculates the arc tangent of the quotient of two numbers. atan2(y,x) returns the arc tangent of y/x. Syntax atan2(y,x) y,x Numbers that produce the quotient for which the arc tangent is to be calculated. close - Close file or pipe close closes the specified file or pipe. Syntax close(expr) expr Name of the file or pipe to be closed, see redirection under the section “printf Formatted output” on page 140. cos - Cosine cos calculates the cosine of a number. Syntax cos(x) Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 x Number for which the cosine is to be calculated. exp - Exponential function exp calculates e to the power of x. Syntax exp(x) x Number for which ex is to be computed. U22794-J-Z125-6-76 135 awk, Functions getline - Read a record awk retrieves a record as directed (see also the control-flow statement next on page 131). getline has several different formats, with the following return values: 1 successful execution 0 end-of-file -1 error Syntax getline awk reads the next input record from the input file into $0. NR, NF, FNR, $0, and $1 to $NF are reset. Example If a record contains %%%, the next record is read. In other words, input records containing %%% are ignored. /%%%/ {getline} Syntax getlineË<Ëfile awk reads a record from the named file into $0. NF, $0, and $1 to $NF are reset. file Name of the file from which a record is to be read. Syntax getlineËvar awk fetches the next input record from the input file and puts it into the variable var. NR and FNR are reset. var Variable into which the next record is to be read. Syntax getlineËvarË<Ëfile awk fetches a record from the named file and puts it into the variable var. NR, NF, FNR, $0, and $1 to $NF remain unchanged. var Variable into which the record is to be read. file Name of the file from which the record is to be read. 136 U22794-J-Z125-6-76 Syntax commandË|ËgetlineË[var] The output of the named command is redirected to getline. Each getline call in this format causes awk to read the next line from the output of command and write it into $0 or the variable var. If var is specified, NR, NF, FNR, $0, and $1 to $NF remain unchanged; if not, NF, $0, and $1 to $NF are reset. 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Functions This construct is equivalent to calling the C function popen() with mode r. var Variable into which the record is to be written. var not specified: The record is written into $0. command Name of the command whose output is to be read. gsub - Global substitution function gsub globally substitutes the string repl for all strings in $0 or instr that match the extended regular expression RE. gsub returns the number of substitutions Syntax gsub(re,repl[,instr]) re Extended regular expression that specifies the pattern to be matched. repl String to be substituted for the strings that match re. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 instr String in which the substitution is to be made. instr not specified: Substitution is done in $0. index - Search for substrings index searches for a substring within a string. If the substring is present, index returns the starting character position (numbered from 1 onward) of its first occurrence in the string; if not, it returns a value of 0. Syntax index(str1,str2) str1 String in which index looks for the substring. str2 Substring that index looks for. U22794-J-Z125-6-76 137 awk, Functions Example Comparing the string "ToTo-LoTo" with "To" index("ToTo-LoTo","To") returns 1. int - Truncate to integer int returns the largest integer equal to or smaller than the argument. Syntax int(x) x Number that is to be truncated to its integer part. length - Return length length returns the length of a string. Syntax length[(str)] str length returns the length of string str. str not specified: length returns the length of the current input record $0. log - Logarithm log calculates the natural base e logarithm. Syntax log(x) x Number whose natural log is to be computed. match - Match regular expressions match checks whether a string in str matches the extended regular expression in re. If a matching string is found, match returns the character position in str (numbered from 1 onward) at which the string begins; if not, it returns 0. The variable RSTART is set to the return value of match; RLENGTH is set to the length of the matching string (or -1 if no matching string is found). Syntax match(str,re) str String in which the pattern is to be matched. re Extended regular expression. 138 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Functions print - Standard output function print is the standard output function. print outputs either the current record or the specified arguments and terminates its output with the output record separator ORS. For further details refer to page 140. Syntax print(arg1[[,]arg2]...)[redirection] No argument specified: print writes the current input record on standard output. arg1arg2 Arguments that are to be printed. print evaluates the expression arguments and concatenates the results in the order in which the arguments are specified. arg1,arg2 Arguments that are to be printed. print outputs the evaluated expression arguments in the specified order, separated by the output field separator OFS if they are separated by commas in the print statement. redirection Output can be redirected to a file or piped to a program. You can use up to 10 output files. redirection can be in the form of: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 >, >>, name of program >file The output is written to the named file. The former contents of file are deleted the first time print is called. All subsequent print or printf outputs to file in the same awk program are appended to the end of file. Unless explicitly closed, file remains open until the end of the awk program. >>file The output is appended to the previous contents of file. Unless explicitly closed, file remains open until the end of the awk program. |prog The output is piped to the program named prog. You are only permitted to open one pipe to prog within an awk program, but you can pipe any number of print or printf outputs to it. This construct is equivalent to calling the C function popen() [4] with mode w. Unless explicitly closed, the pipe remains open until the end of the awk program. The file or program name can specified directly (enclosed in "...") or via a variable that evaluates to the file name. U22794-J-Z125-6-76 139 awk, Functions ! Caution! If you redirect output to the input file, the input file will be destroyed without any warning! Output format print outputs integers in decimal and prints strings at full length. Apart from that, the output format is contingent on the following predefined variables: OFS - output field separator OFS is one space by default. If you wish, you can assign any one character to OFS to change the output field separator. ORS - output record separator ORS is the newline character by default. If you wish, you can assign any one character to ORS to change the output record separator. OFMT - floating point output format OFMT defines the output format for floating point values and is set to "%.6g" by default. This means that the fractional part of a floating point number is printed with a maximum of 6 places. If you wish, you can assign a different printf format for floating point numbers to OFMT (see „printf - Formatted output“ below). Example Print the first and second fields, separated by a blank: {print $1,$2} Example Concatenate the first and second fields without an output field separator: {print $1$2} or {print $1 $2} printf - Formatted output printf is the output function for formatted output. The output format can be specified as in the standard printf() function in C. Syntax printf(format,arg,...)[redirection] format String defining the output format. The output format comprises plain characters and format elements (conversion specifications). Printable characters are output unaltered. The special characters listed in the "Basic elements" section are converted immediately. For example, \n sets the position to the start of the next line. 140 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Functions 7. Juli 2009 Stand 11:58.26 All format elements begins with the percent sign. The most common format elements are presented in the following table: Format element Meaning %c single character %d decimal integer %e floating point number in exponential notation, e.g. 5.234e+2 %f floating point number, e.g. 52.34 %g %e or %f, whichever is shorter %o octal integer (base 8) %s character string %u unsigned decimal integer %x hexadecimal integer (base 16) arg Arguments that are to be printed. printf evaluates the expression arguments, allocates them in the given order to the specifications in format, and outputs them in the appropriate format. – If the format element is incompatible with the argument, e.g. a numeric format specification for an alphanumeric argument, a 0 is printed. – If there are more arguments than format elements, the excess arguments are ignored, i.e. not printed. – If there are more format elements than arguments, an error message is issued. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 redirection Redirection is as for print. redirection not specified: printf prints on standard output. Example Field 1 is printed as a decimal number with at least 2 positions, followed by ** as a separator, followed by field 2 as a string of at least 5 characters, followed by newline: { printf("%2d**%5s\n", $1,$2) } rand - Return a random number rand returns a random number r, where 0 <= r < 1. Syntax rand Also refer to srand. U22794-J-Z125-6-76 141 awk, Functions sin - Sine sin returns the sine of a number. Syntax sin(x) x Number whose sine is to be computed. split - Subdivide strings split divides a string into substrings and stores each substring as an element in an array. The elements are subscripted in ascending order, starting with 1. split returns the number of array elements. Syntax split(str,array[,sep]) str String that is to be split. array Name of the resulting array. sep Extended regular expression specifying the characters that act as a separator between the substrings in str. sep not specified: FS is used as the separator. Example The input: { s=split("january:february:march", months, ":"); for(i=1; i $5' file Since no action has been specified, awk prints the selected lines by default. Example 2 Print every 10th line of a file: $ awk '(NR % 10) == 0' file Example 3 Print the second to last and the last field in each line, separated by a colon: $ awk 'BEGIN {OFS=" :"} \ data-cf-modified-69624cbb415b9fdb2571e9be-=""> {print $(NF-1), $NF}' file If a line consists of a single field, the entire line is output twice, separated by a colon (first $0, then $1). U22794-J-Z125-6-76 145 awk, Examples Example 4 Add up the values of the first field of every line and print the total and average at the end: $ awk '{s += $1} \ > END {print "Total: ", s, "Average: ", s/NR}'\ > file Example 5 Find a preprocessor if directive, i.e. a range of lines in which the first line begins with #if and the last line with #endif: $ awk '/^#if/, /^#endif/' file Example 6 Print all lines in which the first field differs from that of the previous line: $ awk '$1 != prev { print; prev = $1 }' file Example 7 file contains a list of data about young people, with the second field containing one of the entries school, university, apprenticeship or elsewhere. For statistical purposes, you want to count how many are at school and university: $ awk '$2 ~ /school/ {incr["school"]++} > $2 ~ /university/ {incr["university"]++} > END {print "school:" incr["school"]; \ > print "university:" incr["university"]} ' file Example 8 The file contents lists the table of contents of a text. The table of contents is organized in decimal classification and has the format: 1. Foreword 2. Introduction 3. The Game of Chess 3.1. History 3.2. Rules 3.2.1 Setting Up the Figures . . . 4. The Game of Checkers/Draughts 4.1. History . . . 8. Index The following awk program can be used to give the list a more orderly format: $ awk '{$1=$1" "; \ > $1=substr($1,1,6); \ > print $0} ' contents >> con.form 146 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.26 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoa.doc awk, Examples The output lines are prepared in the following stages: First, six blanks are added to the end of the first field ($1=$1ËËËËËË"). Then the first field is truncated to six characters. Thus the first field of each line is 6 characters long, and field 2 always starts at column 7. The output in the file con.form will be as follows: 1. 2. 3. 3.1. 3.2. 3.2.1 . . . 4. 4.1. . . . 8. Foreword Introduction The Game of Chess History Rules Setting Up the Figures The Game of Checkers/Draughts History Index Example 9 The following awk program in the file prog prints the number of fields and the actual fields of each record. The record separator has been redefined as the dollar sign. The field separators are thus blanks, tabs, and the newline character: BEGIN { RS="$"; printf "Record\tNum" } { printf ("\n%4d\t%3d\t", NR, NF); for(i=1;i<=NF; i++) printf "%s:", $i } END {print"\n"} Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The file text contains the following text: first record$ second $ fourth and last record$ record $ The call: $ awk -f prog text returns: Record 1 2 3 4 5 U22794-J-Z125-6-76 Num 2 2 0 4 0 first:record: second:record: fourth:and:last:record: 147 awk, Examples Example 10 You now change the file text to: && first&&record$second record$$fourth and& last record& and call awk again, this time using the -F option to change the field separator to &. $ awk -F"&" -f prog text The output returned is: Record 1 2 3 4 Num 6 1 0 8 :::first::record: second record: fourth:and::last::record::: This example illustrates how fields are separated when a non-standard separator is used. The first line (&&) of the text file is a part of the first record and now yields 3 fields, for example, because each individual separator in a string of separators (&&) is counted, and the newline implicitly acts as a separator as well (2 & + 1 newline = 3). See also 148 egrep, fgrep, grep, lex, sed U22794-J-Z125-6-76 basename return non-directory portion of path name You can use basename to 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc basename – extract the basic file name (basename) from the full path name, – strip any suffixes from the file name. basename strips all characters up to and including the last / from the specified string and writes the result to standard output. The basic file name can thus be separated from its path prefix. If you also specify a string suffix as a command-line argument, basename will strip this suffix as well. basename is useful in shell scripts. Syntax basename[Ëstring[Ësuffix]] string string can be any character string. basename deletes all characters up to and including the last / from string and writes the result to standard output. Strings that do not include a slash are output unmodified. string not specified: A period (dot) is written to standard output. suffix suffix can be any character string. If the specified suffix matches the end of string, string is output without suffix. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of basename: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH U22794-J-Z125-6-76 Determine the location of message catalogs for the processing of LC_MESSAGES. 149 basename Example 1 The name prog is to be generated from /home/catherine/program: $ basename /home/catherine/program ramm prog Example 2 The following shell script compiles a C source program. basename generates the name of the compiled program from the file name used as a command-line argument for the shell script. The compiled program is stored in an executable file in the current working directory. The shell script is called compile. Contents of compile: c89 -o `basename $1 .c` $1 If you call compile as follows: $ compile /home/anna/cprogs/tab.c then the name of the C source file is passed to the command c89 (control program for the compiling and linking of C programs, see c89 [5]) in the positional parameter $1. The shell replaces the operand for the c89 option -o with the result of the basename call. The name of the executable file is tab. See also 150 dirname, ed U22794-J-Z125-6-76 batch execute commands at a later time batch reads commands from standard input, puts them in a queue, and executes them when system load level permits. Standard output and standard error output of the commands to be executed are sent to the user by mailx unless they are redirected elsewhere. The environment variables, the current directory, the permissions for new files (see section “umask get or set the file mode creation mask” on page 778) and the maximum permissible file size (see section “ulimit set or report file size limit” on page 775) are retained, but open files and priorities are lost, and the trap command (shell built-in for catching signals) is deactivated. 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc batch batch writes the job number and the schedule time to standard error. Jobs scheduled with batch are retained even if the user who scheduled them closes the POSIX shell with exit or if the POSIX subsystem is shut down. There is no need to reschedule the jobs. batch has exactly the same effect as at -qb with no further options. Before the call The user ID must have a standard account number for rlogin access. This standard account number can be assigned using the ADD-USER, MODIFY-USER-ATTRIBUTES or ADDPOSIX-USER command. If the file /usr/lib/cron.d/at.allow exists, you can only use batch if your login name appears in it. If the file /usr/lib/cron.d/at.allow does not exist, you can only use batch if your login name does not appear in the file /usr/lib/cron.d/at.deny. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If neither /usr/lib/cron.d/at.allow nor /usr/lib/cron.d/at.deny exists, only the POSIX administrator is allowed to use batch. If only an empty deny file exists, for example, everyone is allowed to use batch. Only the POSIX administrator is allowed to create and modify the allow and deny files. Each line in these files contains precisely one login name. Syntax batch Ú command ... Ú [END] or @@d command Any command or shell script. You can specify more than one command at a time, using semicolons or newlines to separate them. The resulting command list is executed under a single job number. U22794-J-Z125-6-76 151 batch Error at: you are not authorized to use at. Sorry. Permission to use batch denied (see Before the call above). File /usr/lib/cron.d/at.allow List of login names with permission to use batch. One login name is entered per line. /usr/lib/cron.d/at.deny List of login names explicitly denied permission to use batch. One login name is entered per line. /var/spool/cron/atjobs Directory containing a separate file for each batch job which has not yet been executed. Each batch job is allocated a file of its own with the file name jobnumber.b. Variable SHELL Determine a name of a command interpreter to be used to invoke the at job. If the variable is unset or null, sh will be used. If it is set to a value other than a name for sh, the implementation will do one of the following: use that shell; use sh; use the login shell from the user database. TZ Determine the timezone. The job will be submitted for execution at the time specified be timespec or -t time relative to the timezone specified by the TZ variable. If timespec specifies a timezone, it will override TZ. If timespec does not specify a timezone and TZ is unset or null, an unspecified default timezone will be used. Locale The following environment variables affect the execution of batch: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. LC_TIME 152 Determine the format and contents for date and time strings written by batch. U22794-J-Z125-6-76 NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. In the following example, the standard input is redirected, and batch takes its work from the file jobs: $ batch < jobs job 604763316.b at Mon Mar 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc batch 9 14:48:36 2009 The jobs contained in the file jobs are run in sequential order as background processes by batch. When the job is complete, you can have the result displayed on the screen by mailx. at, crontab, mailx, ulimit Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 153 bc bc arbitrary-precision arithmetic language You can use bc to perform arithmetical calculations. bc is an interactive program for a C-like input language. Syntax bc[Ë-l][Ëfile...] -l -l stands for /usr/lib/lib.b, which is a library containing bc programs for various mathematical functions. The -l option must be specified if you want to use any the following functions: s(x) sine c(x) cosine e(x) base e exponential function l(x) natural logarithm a(x) arctangent j(n,x) n-th order Bessel function file Name of file containing a bc program. You may specify more than one file. When all statements from all files have been processed, bc reads from standard input. You can then enter further statements. file not specified: bc reads from standard input. Elements of bc programs A bc program consists of – definitions – statements – comments The following symbols are used in defining the structure of bc programs: L (L - letter) stands for one of the letters a-z E (E - expression) stands for an expression S (S - statement) stands for a statement Comments Comments are enclosed in /*...*/ as in C. 154 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bc Statements Statements in bc can be: ● Expressions (see Expressions) The value of a statement that is an expression is printed unless the main operator is an assignment. ● Blocks (grouped statements): {S; ...; S} ● Conditional statement: if (E) S If expression E is true, i.e. has a non-zero value, then statement S is executed. ● ● Iteration statements: – while (E) S Expression E is evaluated and if it has a non-zero value, statement S is executed. E is then evaluated again, and S is executed again if E is still non-zero. This process is repeated for as long as E has a non-zero value. – for (E; E; E) S First, the first expression is evaluated. Next, the second expression is evaluated and if it has a non-zero value, statement S is executed. Lastly, the third expression is evaluated. Then the second expression is evaluated again and statement S is again executed if it is non-zero, and so on. Unlike in C programs, a for statement must always contain three expressions. Jump statement: break Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The break statement can be used only within an iteration statement. It causes termination of the nearest while or for statement. Program execution continues with the statement that follows the terminated iteration statement. ● Termination statement: quit The quit statement stops execution of a bc program. The quit statement is interpreted as soon as it is read, not when the bc program is executed. Example The following bc program terminates immediately without printing the value of a: a=5 if (a>10) quit a) You can separate statements from one another with a semicolon or a newline character. U22794-J-Z125-6-76 155 bc Expressions Expressions consist of operands and operators. Operands are names or arbitrarily long numbers with optional sign and decimal point. Names L simple variables L function names L[E] array elements ibase base (radix) for input numbers, default: 10 obase base (radix) for output numbers, default: 10 scale number of fractional digits, default: 0 If arrays are used as function arguments or defined as automatic variables, empty square brackets must follow the array name. The same name may be used simultaneously for an array, a function, and a simple variable. All variables are global to a bc program. Other operands (E) result of E sqrt(E) square root of E length(E) number of significant decimal digits in E scale(E) number of fractional digits in E L(E, ...,E) Operators 156 +-*/ addition, subtraction, multiplication, division ^ power operator % remainder of integer division (can now also be applied to floatingpoint numbers. ++ - - increment and decrement operators, which can be applied to names in prefix or postfix notation < <= == >= > != relational operators (less than, less than or equal to, equal to, greater than or equal to, greater than, not equal to) = assignment operator U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bc =@ compound assignment operators, where a=@b is the same as a=a@b. @ can be any of the operators + - * / ^ or %. The logical operators && and || are not recognized by the bc command. Function definition define L (L, ...,L) { auto L, ...,L S; ...;S return (E) } Example define p(x) { auto q q = p * p return (q) } Declaring the identifiers of a function as auto restricts their scope to that function. All function arguments are passed by value. Functions in the math library /usr/lib/lib.b Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Definitions of the mathematical functions listed below are contained in the library /usr/lib/lib.b. The functions can be accessed by calling bc with option -l. s(x) c(x) e(x) l(x) a(x) j(n,x) sine cosine base e exponential function natural logarithm arctangent n-th order Bessel function x values in mathematical functions must be specified in absolute radian measure. If you have write permission for /usr/lib/lib.b, you can add definitions of further functions and also modify or delete existing ones. Defining bases for input and output numbers With ibase and obase you can specify the base used for interpreting input and output values (input and output number radix). The following rules apply: 1. If you do not explicitly assign values to ibase and obase, input numbers are interpreted as decimal and results are output in decimal. U22794-J-Z125-6-76 157 bc 2. If you have already defined the input base with an ibase=n statement, the number that you use to define the output base in an obase=m statement must be in input base n as well. Example The input base is to be 2, the output base 16: $ bc ibase=2 obase=10000 10100000/1010 10 Fractional digits Each expression E in bc is associated with a specific number of fractional digits. You can use the scale variable to inspect or change this number and the scale(E) function just to inspect it. Example In the following example the value of operand a is divided by the value of operand b with the scale variable initially left unset: the result contains no fractional digits. Then scale is assigned a value of 8: the result of the division is now correct to 8 places after the decimal point. Finally we inspect the number of fractional digits in the result and the value of scale. $ bc a=15.0 b=7.8 a/b 1 scale=8 a/b 1.92307692 scale(a/b) 8 scale 8 @@d or [END] $ If you join two expressions using an operator, the number of fractional digits associated with the result is governed by a rule specific to the operator you use. The rules for bc operators are described below. Various symbols are used in the descriptions: 158 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bc a = first operand b = second operand R = number of fractional digits in the result of a calculation A = scale(a) B = scale(b) - The unary minus sign and the increment and decrement operators ++ and -- (in prefix ++ and postfix notation) do not affect the number of fractional digits. -Rule: scale(E) = scale (-E) = scale(--E) = scale(++E) ... Example a is assigned a value with three fractional digits. The query function scale(a) here always returns 3, regardless of whether a has a -, -- or ++ operator and regardless of the fact that scale was previously assigned a different value: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ bc scale=1 a=1.123 scale(a) 3 scale(-a) -3 scale(a++) 3 scale(--a) 3 @@d or [END] $ + - With the binary operators + and -, R is equal to the number of fractional digits in the operand with the most fractional digits, regardless of whether you have previously assigned scale some other value. Rule: R = max(A,B) Example The scale variable is assigned a value of 1. Operand a is assigned a value with 2 fractional digits, b a value with three fractional digits. Thus b has more fractional digits than a, and also more than scale. The query function returns 3 for both operands, the greater number in b taking precedence. $ bc scale=1 a=0.12 b=0.123 U22794-J-Z125-6-76 159 bc scale(a+b) 3 scale(b-a) 3 @@d or [END] $ * With multiplications, a value previously assigned to scale is significant: bc first calculates max, which is the highest of the values scale, A and B. It then forms the sum of A and B and compares this value with max. R is then the lower (min) of these two values. Rule: R = min (A+B, max (scale, A, B)) Example scale has a value of 9, A and B are both 1. Thus the highest of the three values is 9. The sum of the number of fractional digits in the two operands is 2. The number of fractional digits in the result of the multiplication is the lower from the comparison of max and this sum, which is 2. $ bc scale=9 a=0.1 b=0.1 scale(a*b) 2 @@d or [END] $ / With divisions, the precision of the result is equal to the value of scale: Rule: R = scale Example scale is first given a value of 8. Then the operands are assigned integer values. The result is also an integer. In spite of that, the query function returns 8, and the result is shown correct to 8 places after the decimal point. $ bc scale=8 a=16 b=4 scale(a/b) 8 a/b 4.00000000 @@d or [END] $ ^ 160 With the power operator, R is formed as follows: U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bc – If the integer exponent e is equal to or greater than 0: bc takes the higher (max) of the two values scale and A. It then multiplies A by the absolute value m of the exponent, compares the result with max, and takes the lower of the two values. Rule: R = min (A*m, max (scale, A)) – If the integer exponent e is less than 0: The precision of the result is equal to the value of scale. Rule: R = scale Example 1 scale is given a value of 7. a has one fractional digit, and the absolute value of exponent e is 4, i.e. greater than 0. The higher value from the comparison of scale and a is 7. However, the result of multiplying a and m is 4. Thus the number of fractional digits after exponentiation is 4: $ bc scale=7 a=3.1 e=4 scale(a^e) 4 a^e 92.3512 @@d or [END] $ Example 2 © cognitas GmbH 2001-2007 However, if you set the exponent e to -4, the number of fractional digits is equal to the value of scale: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 $ bc scale=7 a=3.1 e=-4 scale(a^e) 7 a^e .0108281 @@d or [END] $ U22794-J-Z125-6-76 161 bc = =@ With the assignment operators, the value of R is equal to that of A after assignment. For a given compound operator =@, the rule for calculating the number of fractional digits is the same as for the corresponding simple operator @. Rules: R = scale(b) and R = scale(a@b) Example 1 a is assigned a number with one fractional digit, b a number with two fractional digits: scale(a) is 1 and scale(b) is 2. If you inspect scale(a) after assigning the operands, bc returns a value of 2, which is scale(b). If you then inspect a again, the value returned is the value assigned to b: $ bc a=0.1 b=0.12 scale(a) 1 scale(b) 2 a=b scale(a) 2 a .12 @@d or [END] $ Example 2 a is assigned a number with two fractional digits, b a number with three. In the ffunction call, a is assigned the value resulting from adding the two operands. bc sees the number of fractional digits in the result of an addition as being equal the number of fractional digits in the operand with the most fractional digits. After assignment a has the same number of digits, i.e. three: $ bc a=0.12 a=0.123 scale(a) 2 scale(b) 3 a=+b scale(a) 3 162 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bc a .243 @@d or [END] $ % With remaindering, if the value of scale is non-zero, the result is computed as follows: 7. Juli 2009 Stand 11:58.27 a%b = a - (a / b) * b First the division is performed using the precision of scale. The precision of the multiplication by b is equal to: scale + B In other words the multiplication is performed with full precision. Thus here the % operator can be used as a measure of the precision with which the division is performed. Finally R is whichever is the higher of A and (scale + B). Rule: R = max ((scale + B), A) Example Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 scale has a value of 4, a and b each have one fractional digit. The result of remaindering has five fractional digits: $ bc scale=4 a=1.2 b=1.1 scale(a%b) 5 a%b .00001 @@d or [END] $ File /usr/lib/lib.b Math library Locale The following environment variables affect the execution of bc: LANG U22794-J-Z125-6-76 Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. 163 bc LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Addition, subtraction, multiplication, and division of numbers. Non-integer results are to have 2 digits after the decimal point: $ bc scale=2 3+7 10 8-15 -7 7*6 42 3/5 .60 quit $ Example 2 Defining a function to compute an approximate value of the exponential function. scale=20 define e(x){ auto a, b, c, i, s a = 1 b = 1 s = 1 for(i=1;1==1;i++){ a = a*x b = b*i c = a/b if(c==0) return (s) s = s+c } } 164 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bc The termination criterion of the for loop is contained in the body of the loop (if(c==0)) and is not given by the second expression of the for statement as is usually the case. In a C program, the second expression of the for statement would simply be omitted; but in a bc program the for statement must always have 3 expressions. The expression 1==1, which is always true, has been inserted for this reason. Example 3 Printing approximate values of the exponential function of the first ten integers. for(i=1;i<=10;i++) e(i) Example 4 Printing the squares of the integers 1 to 4: $ bc for(i=1;i<5;i++) {i*i} 1 4 9 16 quit expr, let Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 165 bg bg Built-in sh command run jobs in the background You can use the built-in command bg in the POSIX shell sh to specify jobs for background processing. You should only use this command if you have accessed the POSIX shell via rlogin. i Syntax bg[Ëjob-id...] job-id Each specified job is held for background processing. The section “Jobs” on page 62 describes the format of job-id. job-id not specified: The current job is specified for background processing. Locale The following environment variables have an effect on the execution of bg: LANG Specifies a default value for the locale variable that is unset or null. If LANG is unset or null, the corresponding locale default value is used. If the locale variable contains an invalid setting, locale behaves as if no variables had been set. LC_ALL If this value is set, i.e. is not empty, this value overwrites the values of all other locale variables. LC_CTYPE Determines the locale for the interpretation of byte sequences as characters (e.g. single-byte as opposed to multibyte characters in arguments). LC_MESSAGES Determines the format and content of error messages. NLSPATH Example Determines the position of the message catalog for the processing of LC_MESSAGES. You wish to specify job %1 for background processing: $ bg %1 See also 166 fg, jobs, kill, wait U22794-J-Z125-6-76 bs2cmd execute BS2000 command (BS2000) The POSIX command bs2cmd executes a BS2000 command. Syntax bs2cmd[Ë-h]Ëcmd -h Displays the command syntax and explains the options. 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cmd cmd BS2000 command: Any BS2000 command in accordance with the BS2000 syntax in SDF format may be specified here. (The ISP format is now only supported for compatibility reasons.) Special characters in the BS2000 command (e.g. $, *) must be escaped by a backslash ('\'). Alternatively, the entire cmd string must be enclosed in quotes. The command name, operands and operand values are converted to uppercase letters. For commands in the ISP format, only the command name is converted to uppercase. Hint The bs2cmd command is also supported with rlogin and telnet accesses to POSIX. Unloading the shell: When bs2cmd is called from the base shell, the unloading of the shell is prevented by specifying a corresponding BS2000 command (e.g. START-PROGRAM or a user-defined command whose CALL procedure terminates the running program). bs2cmd issues a message (SDP0250), and the BS2000 command is not executed. The unloading of the base shell cannot be currently prevented on calling bs2cmd from a subshell. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 SYSFILE environment: BS2000 commands that need the SYSFILE environment for execution can be currently executed only in the base shell, since the SYSFILE environment is not fully initialized in a subshell. U22794-J-Z125-6-76 167 bs2cmd Example The following command shows the catalog entries of the SYSRME files on the BS2000 ID $QM212: /home/user1> bs2cmd 'show-file-attributes $qm212.sysrme.*' % % 15 :1OSN:$QM212.SYSRME.ARCHIVE.090.D 15 :1OSN:$QM212.SYSRME.ARCHIVE.090.E . . . % 12 :1OSN:$QM212.SYSRME.POSIX-BC.070.D % 12 :1OSN:$QM212.SYSRME.POSIX-BC.070.E % 18 :1OSN:$QM212.SYSRME.POSIX-BC.080.D % 18 :1OSN:$QM212.SYSRME.POSIX-BC.080.E %:1OSN: PUBLIC: 15 FILES RES= 210 FREE= %:1OSN: PUB/S2: 2 FILES RES= 123 FREE= 18 1 REL= REL= 0 PAGES 0 PAGES /home/user1> See also 168 bs2cp, bs2file U22794-J-Z125-6-76 bs2cp copy POSIX/BS2000 files (BS2000) bs2cp copies files from the POSIX file system to BS2000 and vice versa. The command has four formats: 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp – Copying a single POSIX file to BS2000 and vice versa (see below) – Copying POSIX files to BS2000 as DVS files (see page 172) – Copying POSIX files to a BS2000 PLAM library (see page 173) – Copying BS2000 files with wildcard syntax to a POSIX file directory (see page 174) The command creates physical copies. Hence, after copying the files are physically present in both the POSIX and BS2000 file systems. Format 1 Copying a single POSIX file to BS2000 and vice versa Syntax bs2cp[Ë-k|Ë-tËtable][Ë-f][Ë-l][Ë-h]Ëbs2:fileËfilecopy bs2cp[Ë-k|Ë-tËtable][Ë-f][Ë-l][Ë-h]ËfileËbs2:filecopy -k The file content is converted during copying: – from ASCII to EBCDIC, if file is a file of the POSIX file system – from EBCDIC to ASCII, if file is a BS2000 file (bs2: entered). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 This option is ignored and no conversion is performed if the original file or the file copy is a PLAM library element of the L (LLM) type. Unlike control with the IO_CONVERSION environment variable, -k will convert independently of the POSIX file system type. Hence, it will also convert when the POSIX file system is an EBCDIC file system (i.e. not an ASCII file system or an NFS-mounted file system). -k is only meaningful with text files. The b2cp command does not perform any contents plausibility check for meaningful conversion. -t table The file content is converted during copying using the table file as conversion table. i The options -k and -t are mutually exclusive. This is similar to the option -k in that the option will be ignored and no conversion will take place if the original file or the file copy is a PLAM library element of the L (LLM) type. U22794-J-Z125-6-76 169 bs2cp Properties of the table file: – EBCDIC format. – It must contain exactly 256 character pairs. They must be composed of the following characters: 0 to 9, a to f and A to F. – All EBCDIC characters from X’00’ to X’40’ can be placed between the character pairs. These are for example blank spaces, tabulators or newline characters. – The file can be of any size. However, only the first 8172 characters (max.) are evaluated. If the absolute path name of the table file is not given, the command will look up in $BS2CPTABS. If this variable is not set or is empty, the command will search for the table file in the /usr/lib/bs2cp directory. At first, a 256-byte conversion table is created from the table file during the conversion. This is done by compressing each of the 256 character bytes to a hex decimal character. After that, each of the characters from the file to be copied is replaced by a character from the conversion table which is addressed via the binary value of the input character. The input character M is for example substituted by byte 212 of the conversion table because M has the EBCDIC value X’D4’ and hence the decimal value 212. i -f An example of the structure of the code table can be found under “Example table for option -t” on page 177. By default, stderr is checked during copying from POSIX to BS2000 and the user is prompted if existing BS2000 files/elements should be overwritten or not. This dialog prompt is suppressed with -f and existing files are overwritten. This option is ignored (if indicated) during copying from BS2000 to POSIX. Existing POSIX files are always overwritten. If the environment variable OV exists, the dialog query is omitted regardless of the -f option. If OV = "Y", existing BS2000 files/elements are overwritten, otherwise they are not overwritten and a message is issued instead. -l Each successfully copied file is reported as follows: bs2cp: copy from path name to path name done -h Output of the command syntax with explanation of options. bs2: The file or filecopy entered with this option is a BS2000 file. DVS files are addressed by their name. Special characters (e.g. $ in the BS2000 user ID) in file names must be masked by a preceding backslash character or by bracketing the character strings bs2:file or bs2:filecopy in single inverted commas. 170 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp A library element is called in the following form (also see example 3 on page 181): 'lib(elem [,[type][,vers]])' 7. Juli 2009 Stand 11:58.27 where lib is the name of the PLAM library in BS2000. elem is the name of the element. type is the type of element. The element types S, M, J, P, D, X and L are supported. Default value is S. vers is the version of the element. Default is *HIGH. i One of the files (file or filecopy) must be a BS2000 file or library element. POSIX file directories cannot be copied into BS2000. Wildcard syntax and construction entries are not supported. file Name of the file to be copied. filecopy Name of the copy. If filecopy is an existing BS2000 file or a library element, the user is prompted if it should be overwritten. The option -f and the environment variable OV=Y suppress this prompt. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The following is valid for a filecopy that is a BS2000 DVS file: – If filecopy already exists, bs2cp will adopt the file attributes from the file catalog. – If filecopy does not yet exist, it will be created. Prior to the bs2cp call, the file type of the new file can be set with the ftyp command. If no file type is set, a SAM file with a variable record length will be created. The following is valid if filecopy is an element of a BS2000 PLAM library: – An existing elem library element will be overwritten if the option -f is set or if the environment variable OV is set to Y. – If the elem library element does not yet exist, it will be created. The ftyp and bs2file commands can also be used to influence the file types of non L-type elements. – If no PLAM library with the name lib exists, it will be created. U22794-J-Z125-6-76 171 bs2cp Format 2 Copying POSIX files to BS2000 as DVS files Syntax bs2cpË-x[Ë-k|Ë-tËtable][Ë-f][Ë-l][Ë-h][Ë-pËprefix][Ë-sËsuffix]Ëfile ... Ëbs2: -x Extended format of the bs2cp command. -k -t see format 1 (page 169). -f This is analogous to format 1. By default, stderr is checked during copying and the user is prompted if existing BS2000 files should be overwritten. However, the prompt offers several reply options: bs2cp: overwrite A ? y (yes), n (no), a (all) or q (quit) If q is selected, the command bs2cp is aborted with an exit status unequal to null. The dialog query is suppressed with -f. Already existing files are always overwritten. If the environment variable OV exists, the dialog query is omitted regardless of the -f option. If OV = "Y", existing BS2000 files/elements are overwritten, otherwise they are not overwritten and a message is issued instead. -l Each successfully copied file is reported as follows: bs2cp: copy from path name to path name done -h Output of the command syntax with explanation of options. -p prefix The prefix character string precedes the names of the copies. -s suffix The suffix character string is appended to the names of the copies. file... is a list consisting of one or more POSIX files where shell special characters (wildcards) can be used to generate file names. file must not be a file directory. bs2: The copies are placed in BS2000 as DVS files. The copies always receive the same plain file names as the originals written in upper case. They can, however, be expanded with prefixes and suffixes. Any underscore characters will be converted into dollar signs. If files already exist, the user will be prompted if they are to be overwritten. Moreover, the user can specify that all the following files will be overwritten without any prompt being displayed. It is also possible to cancel processing. By default, the files are copied to the BS2000 user ID of the POSIX user in the home pubset. The prefix entered with -p can be used to indicate another Cat ID or User ID. See example 4 on page 181. 172 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp Format 3 Copying POSIX files to a BS2000 PLAM library Syntax bs2cpË-x[Ë-k|Ë-tËtabelle][Ë-f][Ë-l][Ë-h][Ë-pËpräfix][Ë-sËsuffix]Ëdatei ... Ë’bs2:lib([,[type] [,vers]])’ -x Extended format of the bs2cp command. -k -t see format 1 on page 169. -f By default, stderr is checked and the user is prompted if existing BS2000 elements should be overwritten or not. This dialog prompt is suppressed with -f and existing files will be overwritten. If the environment variable OV exists, the dialog query is omitted regardless of the -f option. If OV = "Y", existing BS2000 files/elements are overwritten, otherwise they are not overwritten and a message is issued instead. -l Each successfully copied file is reported as follows: bs2cp: copy from path name to path name done -h Output of the command syntax with explanation of options. -p prefix The prefix character string precedes the names of the copies. -s suffix The suffix character string is appended to the names of the copies. ’bs2:lib([ ,[type ][,vers]])’ The copies are created as elements of the BS2000 PLAM library lib. For type and vers see page 171. The element names are created from the original simple file names (in upper case). They can be expanded with prefixes and suffixes. See example 5 on page 181. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file... is a list consisting of one or more POSIX files where shell special characters (wildcards) can be used to generate file names. file must not be a file directory. U22794-J-Z125-6-76 173 bs2cp Format 4 Copying BS2000 files with wildcard syntax to a POSIX file directory Syntax bs2cpË-x[Ë-k|Ë-tËtabelle][Ë-l][Ë-h][Ë-pËpräfix][Ë-sËsuffix] Ë’bs2:datei’ | Ë’bs2:lib(elem[,[type][,vers]])’Ëfile directory -x Extended format of the bs2cp command. -k -t see format 1 on page 169. -l Each successfully copied file is reported as follows: bs2cp: copy from path name to path name done -h Output of the command syntax with explanation of options. -p prefix The prefix character string precedes the names of the copies. -s suffix The suffix character string is appended to the names of the copies. ’bs2:file’ file is a fully or partially qualified DVS file name with wildcard syntax (special character "*" of the BS2000 command SHOW-FILE-ATT or FS). Only one bs2:file operand is permitted. Important: If the name consists of blank spaces only or is missing altogether, this is equivalent to the "*" wildcard character. ’bs2:lib(elem [,[type] [,vers] ])’ elem is the fully qualified name of a PLAM element or the partially qualified name of several PLAM elements with LMS wildcard syntax. The following wildcard special characters are supported: * < : >. Other special characters for LMS wildcards are not guaranteed. Special case: If elem is not specified, all elements of the corresponding type and version will be used (this is equivalent to the wildcard character "*"). Minimal entry: bs2:lib() all elements of type S and of highest version are copied. file directory The BS2000 files/elements are copied to the POSIX file directory indicated. The common shell notation is permitted for file directories. For example: . (period) ~ (tilde) /dvz1/dvz2 dvz1/dvz2 Current directory Home directory absolute path Relative path starting at the current directory See example 6 on page 182 and example 7 on page 182. 174 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp Hint EXIT status in the extended formats 2 through 4 If several files are to be copied with the same bs2cp call, the exit status will only be 0 if all copies were successfully completed. As soon as the first error occurs, the exit status will be unequal to 0 and the remaining files will not be copied. Copying library elements When library elements are copied to POSIX files or vice versa, the software product LMS must be installed. DVS file attributes supported bs2cp only supports file attributes which are supported by the C runtime system with STREAM I/O. Hence, SAM files with fixed record length can only be opened as binary type (ftyp binary). ftyp binary supports the following file attributes: FCBTYP RECFORM BLKCTRL BLKSIZE (STD,n) RECSIZE (r Byte) Max. number of data bytes SAM F PAMKEY 1Î n Î16 1Î r În*2048 RECSIZE DATA(2K) 1Î n Î16 1Î r În*2048-16 RECSIZE DATA(4K) 2Î n Î16 V PAM Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 U U22794-J-Z125-6-76 PAMKEY 1Î n Î16 4Î r În*2048-4 RECSIZE - 4 DATA(2K) 1Î n Î16 4Î r În*2048-16 RECSIZE - 4 DATA(4K) 2Î n Î16 PAMKEY 1Î n Î16 BLKSIZE DATA(2K) 1Î n Î16 BLKSIZE - 16 DATA(4K) 2Î n Î16 PAMKEY 1Î n Î16 BLKSIZE DATA(2K) 1Î n Î16 BLKSIZE - 12 DATA(4K) 2Î n Î16 NO(2K) 1Î n Î16 NO(4K) 2Î n Î16 BLKSIZE 175 bs2cp ftyp text supports the following file attributes: FCBTYP REC-FORM BLKCTRL BLKSIZE (STD,n) RECSIZE (r Byte) Max. number of data bytes SAM V U ISAM V PAMKEY 1Î n Î16 4Î r În*2048-4 RECSIZE - 4 DATA(2K) 1Î n Î16 4Î r În*2048-16 RECSIZE - 4 DATA(4K) 2Î n Î16 PAMKEY 1Î n Î16 BLKSIZE DATA(2K) 1Î n Î16 BLKSIZE - 16 DATA(4K) 2Î n Î16 PAMKEY 1Î n Î16 12Î r În*2048 RECSIZE - 12 DATA(2K) 1Î n Î16 12Î r În*2048 RECSIZE - 12 DATA(4K) 2Î n Î16 The record keys of ISAM files are not transferred. It is not possible to copy temporary files from BS2000 or via remote file access. 176 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp Example table for option -t 7. Juli 2009 Stand 11:58.27 Structure of a EBCDIC standard table. A target file is created with a 1:1 copy of the source file: Error 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA on AC AD AE AF B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE FF path name : Permission denied Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 You do not have read permission for this file or you do not have write permission for the file directory. path name : no such file or directory The file or file directory indicated does not exist. path name : is a directory The name entered describes a file directory and not a file. path name : DMS FSTAT error xxx Too many files have been entered. invalid character pair: xx (valid only 0, ..,9,A,..,F) An erroneous conversion table was indicated with option -t. incorrect number of character pairs: xxx (must be 256) An erroneous conversion table was indicated with option -t. more than 256 character pairs given An erroneous conversion table was indicated with option -t. U22794-J-Z125-6-76 177 bs2cp do not use options -k and -t at the same time The options -k and -t cannot be used at the same time. file name name invalid in this case A name was indicated after bs2: in format 2. element name name invalid in this case An element name was given in format 3. invalid target name path name The name of the target file contains an "*". lib(elem,type,vers) already exists The output library element already exists. (The -f option was not specified, the environment variable OV does not exist, and the entry takes place from stdin (-).) lib(elem,type,vers) not accessible The output library element cannot be accessed. You either have no write authorization for the library or for the element, or lib is not a PLAM library. file already exists The BS2000 output file already exists. (The -f option was not specified, the environment variable OV does not exist, and the entry takes place from (-).) path name: is a directory The path name specified refers to a directory. path name is not an executable file An attempt was made to copy a POSIX file which does not have the format (UFS-LLM) of an executable file into a library as an L element. closing bracket missing The closing bracket is missing in the element specification. (An opening bracket was found.) Copy from DMS file to DMS file not supported - use command /COPY-FILE f1,f2 Copying a BS2000 file to a BS2000 file is not supported. The /COPY-FILE command must be used for this purpose. Copy from UFS file to UFS file not supported - use command cp f1 f2 Copying a POSIX file to a POSIX file is not supported. The POSIX command cp must be used for this purpose. Copy of UFS directories is not supported . or .. was specified as file. DMS FSTAT error Dxxx The system function FSTAT for a BS2000 file returns the error code Dxxx. element name elem too long The element name (format 2, 3 or 4) specified as the source is longer than 64 characters. 178 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp FILE command for "filename" returned error The FILE command for the BS2000 output file returned an error. A message of the FILE command was output immediately beforehand. (The message is connected to a bs2file or ftyp command which was issued by the user beforehand.) file filename not found The BS2000 input file was not found. Invalid BS2000 filename: file The specified file name ends with a . (period). invalid character in elem The specified element name contains illegal characters. invalid element name elem The element name elem starts or ends with . or -. LMS error - LMSnnnn[, PLAmmmm][, DMS or macro RC xxxx] (fct=fct, lib=lib, elem=elem, type=type, ver=vers, file=filename) When a library element is accessed, LMSUP reports an error with the error code LMSnnnn, possibly supplemented by the PLAM error code and/or the DMS or macro error code (the meaning of the error codes can be inquired using bs2cmd help LMSnnnn etc.). The second line is output only if the -l or -x option was specified. fct is ADD, SEL or TOC. When fct=TOC, the filename specification remains empty. LMS end errorcode xx LMSUP, which is needed to copy library elements, could not be terminated properly. LMS init errorcode xx LMSUP, which is needed to copy library elements, could not be initialized. LMS toc errorcode xx Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The library’s directory could not be read any futher. LMS tocprim errorcode xx The library’s directory could not be read. No POSIX file involved - use utility LMS A library element and a BS2000 file were specified as the source and the destination or vice versa. No write of file. OV is set to value The specified BS2000 file was not overwritten because the -f option was not specified and the environment variable OV is set and not equal to "Y". No write of lib(elem,type,vers). OV is set to value The specified element was not overwritten because the -f option was not specified and the environment variable OV is set and not equal to "Y". U22794-J-Z125-6-76 179 bs2cp opening bracket missing The opening bracket is missing in the element specification. (A closing bracket was found.) PLAM element elem, type type, version vers not accessible The input element which is specified as the source cannot be accessed. You either have no read authorization for the library or the element, or lib is not a PLAM library. PLAM element elem, type type, version vers not found The input element specified as the source was not found. PLAM element name longer than 64 The specified element name is longer than 64 characters. PLAM element name missing The element name is missing in the element specification for format 1. PLAM element version longer than 24 The specified element version is longer than 24 characters. PLAM element version vers invalid The version specification vers contains illegal or wildcard characters. PLAM element type not supported The specified type is not S, M, J, P, D, X or L. PLAM error - PLAmmmm[, DMS or macro RC xxxx] (fct=fct, lib=lib, elem=elem, type=type, ver=vers, file=filename) When a library element is accessed, PLAM reports an error with the error code PLAmmmm, possibly supplemented by the DMS or macro error code (the meaning of the error code can be inquired using bs2cmd help PLAmmmm etc.). The second line is output only if the -l or -x option was specified. fct is ADD or SEL. PLAM library name missing The library name is missing in the element specification. PLAM library name longer than 54 The library name is longer than 54 characters. PLAM library lib not found The specified PLAM library does not exist. PLAM names must end with single closing bracket The element name ends with more than one closing bracket. too many opening brackets The element specification contains more than one opening bracket. too many tokens within brackets The element specification contains more than three elem, type, vers specifications separated by commas. 180 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2cp Example 1 Copy the BS2000 techdoc file into the file directory /usr/fl, using the same file name. The character set should converted from EBCDIC to ASCII (option -k). $ bs2cp -k bs2:techdoc /usr/fl/techdoc Example 2 Copy the techdoc file in the POSIX file system to BS2000, using the file name flcopy. The current character set is retained (no option -k). $ bs2cp techdoc bs2:flcopy Example 3 The documentation file is a D-type element in the BS2000 PLAM library product. Copy the element to the file directory /usr/product. $ bs2cp 'bs2:product(documentation,D)' /usr/product/documentation Example 4 $ bs2cp -x -p posix. -s .sich /home/do/sich/dat* bs2: bs2cp: overwrite FILE1 ? [y=yes/n=no/a=all/q=quit] a $ ls /home/do/sich file1 file2 file3 $ bs2cmd fstat posix. 12 :ABCD:$USER.POSIX.FILE1.SICH 9 :ABCD:$USER.POSIX.FILE2.SICH 18 :ABCD:$USER.POSIX.FILE3.SICH Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example 5 $ ls genpos.c hrcv.c $ bs2cp -x -l -p p bs2cp: copy from bs2cp: copy from bs2cp: copy from hrcv.s hrmgt.c hrupos.c hsdax.c hr*.c ’bs2:clib(,s,300)’ hrcv.c to CLIB(PHRCV.C,S,300) done hrmgt.c to CLIB(PHRMGT.C,S,300) done hrupos.c to CLIB(PHRUPOS.C,S,300) done Creates the PLAM library CLIB with the following content: TYPE NAME VER (VAR#) date (S) PHRCV.C 300 (0001) 2008-05-27 (S) PHRMGT.C 300 (0001) 2008-05-27 (S) PHRUPOS.C 300 (0001) 2008-05-27 U22794-J-Z125-6-76 181 bs2cp Example 6 $ bs2cmd fstat ’$user2.*kvh*’ 9 12 12 :ABCD:$USER2.AKVH7 :ABCD:$USER2.KVHMEM :ABCD:$USER2.ZKVH $ bs2cp -x -s .c ’bs2:$user2.*kvh*’ /home/tag/kvh $ ls -l /home/tag/kvh total 12 -rw-r--r-- 1 kvh prod5 -rw-r--r-- 1 kvh prod5 -rw-r--r-- 1 kvh prod5 2321 May 27 13:56 akvh7.c 18549 May 27 13:56 kvhmem.c 971 May 27 13:56 zkvh.c Example 7 From the BS2000 PLAM library $USER2.DOCLIB, all elements of type D, file names starting with KVH and version 300 are to be copied to the file directory /home/usr/doc. The prefix doc. is to precede the names of the copies. $ bs2cp -xl bs2cp: copy bs2cp: copy done bs2cp: copy -p doc. 'bs2:$user2.doclib(kvh*,d,300)' /home/usr/doc from $USER2.DOCLIB(KVHGEN,D,300) to /home/usr/doc/doc.kvhgen done from $USER2.DOCLIB(KVHPROD,D,300) to /home/usr/doc/doc.kvhprod from $USER2.DOCLIB(KVHZ,D,300) to /home/usr/doc/doc.kvhz done $ ls -l /home/usr/doc total 12 -rw-r--r-1 kvh -rw-r--r-1 kvh -rw-r--r-1 kvh See also 182 prod5 prod5 prod5 21738 May 31 06:21 doc.kvhgen 7461 May 31 06:21 doc.kvhprod 11729 May 31 06:21 doc.kvhz bs2file, ftyp U22794-J-Z125-6-76 bs2do calling BS2000 procedures from the POSIX shell (BS2000) The BS2000 procedure to be executed is started in an ENTER-JOB with the CALLPROCEDURE command. bs2do waits synchronously for the ENTER-JOB to terminate. Syntax bs2do[Ë-DV] [Ë-oËoutfile]ËprocedureË[[(]parameter[)]] -D Debug mode - temporary files are not deleted and remain available for diagnosis. 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2do -V Verbose - single steps are logged to stdout. -o the BS2000 system file SYSOUT opened when the ENTER-JOB is started is copied to the POSIX file outfile. outfile name of the POSIX file into which the BS2000 system file SYSOUT is copied when the ENTER-JOB is started. outfile can be any POSIX path name. procedure name of the file containing the BS2000 procedure to be executed. procedure can be any POSIX path name or a string bs2:BS2Name, where BS2Name is a BS2000 procedure name according to the SDF syntax of the operand FROM-FILE of the BS2000 /CALL-PROC command. parameter parameters of the BS2000 procedure to be executed. Entries are made according to the SDF syntax of the PROCEDURE-PARAMETERS operand of the BS2000 /CALL-PROC command, the enclosing parentheses being optional. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 i File The following applies to procedure and parameter: special characters (e.g. (, ), $) are to be masked for the shell. bs2do does not interpret the operands, e.g. among other things keywords in keyword parameters are not converted to uppercase. Input files: – stdin: not used – procedure file procedure – options file optionfile, where optionfile can be any POSIX path name. By default, /opt/BS2DO/options/bs2doopt.std is installed. Output files: – stdout: output of messages if the option -V (verbose) is specified – stderr: bs2do error messages, contents of the job variable defined in the options file optionfile – BS2000 system file SYSOUT copied to POSIX file outfile, if the -o option is specified Variable BS2DOOPT: POSIX path name of an options file. If the environment variable BS2DOOPT is not defined, the implicitly installed options file optionfile is used. U22794-J-Z125-6-76 183 bs2do Hint Extended description bs2do sets up the batch job #T.pid.ENTER in BS2000, where pid is the POSIX process number of the process executing bs2do. The batch job is initiated with /.DOpid LOGON If the procedure procedure is located in the POSIX file system, it is copied to the BS2000 file T.pid.PRO. The batch job is then started as follows: /ENTER-JOB FROM-FILE=#T.pid.ENTER,PROCESSING-ADMISSION=SAME,HOST=*STD,JOB-CLASS=*STD,JOB-PRIORITY=*STD The operands PROCESSING-ADMISSION, HOST, JOB-CLASS and JOB-PRIORITY can be set via the options file optionfile. In the batch job, the system file SYSOUT is assigned to the file #T.pid.OUT, the job variable #BS2DOJV is set up and then the procedure is called, the name of the #BS2DOJV job variable can be set via the options file optionfile: /CALL-PROC FROM-FILE=T.pid.PRO,PROC-PAR=parameter,LOGGING=NO The LOGGING operand can be set via the options file optionfile. The FROM-FILE operand is only specified if procedure is in the POSIX file system. Otherwise, the string procedure is adopted unchanged. Special characters (e.g. (,),$) are to be masked for the shell. After the procedure procedure terminates, the system file SYSOUT is closed and the POSIX shell is started. /START-PROG SHELL The SHELL operand can be set via the options file optionfile. If no error display was set in procedure (/EXIT-PROCEDURE ERROR=NO), the signal SIGUSR1 is sent to the parent process of the batch job as a terminating message. If the error display was set in the procedure procedure (/EXIT-PROCEDURE ERROR=YES), the value of the job variable #BS2DOJV and the signal SIGUSR2 are sent to the parent process of the batch job as a terminating message. In both cases, if the -o outfile option is specified, the file #T.pid.OUT is first copied to the POSIX file outfile. When the shell terminates, all T.pid files are deleted and the batch job is terminated. All temporary #T.pid files are also deleted. In debug mode (-D option), no temporary files are created, but only T.pid files that are not deleted when the batch job terminates. 184 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2do The options file The structure of the options file is as follows: keyword keyword = value Lines that do not begin with a valid keyword are ignored. Continuation lines are exceptions to this rule. value can be extended beyond the end of a line with the - character. Table of supported keywords: keyword value BS2DOJV Job variable name (optional). If job variables are not offered by the product, no value may be specified for this keyword SHELL Operand of START-PROG for loading the POSIX shell PROCESSING-ADMISSION HOST JOB-CLASS JOB-PRIORITY Corresponds to the operand of ENTER-JOB with the same name LOGGING Corresponds to the operand of CALL-PROC with the same name Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The standard options file /opt/BS2DO/options/bs2doopt.std: # # bs2do controlling job variable # (temporarily in order to allow parallel calls within one user ID) # BS2DOJV = #BS2DOJV # # BS2000 enter-job operands # PROCESSING-ADMISSION = SAME HOST = *STD JOB-CLASS = *STD JOB-PRIORITY = *STD # # BS2000 call-proc operands # LOGGING = NO # # BS2000 shell configuration (POSIX-BC shell with # correction level >= A12 # POSIX-SH shell with correction level # level >= A52) # SHELL = *M($TSOS.SINLIB.POSIX-BC.030.SHELL, SH, RUN-MODE=ADVANCED, PROG-MODE=ANY) # U22794-J-Z125-6-76 185 bs2do Restrictions Since bs2do cannot bypass the BS2000 security mechanisms, restrictions must be observed if PROCESSING-ADMISSION <> SAME is set in the options file: – – – Example The user ID in which the ENTER-JOB is to be executed must have POSIX user permissions. If the -o option is specified, the user ID in which the ENTER-JOB is to be executed must have search and write permissions in the current directory in which bs2do was called. Otherwise, the ENTER-JOB SYSOUT file is not copied to the UFS, even if the -o option is set. The procedure to be executed is not copied from the UFS into another user ID, i.e. executing a procedure under a different user ID is only supported with procedure being equal to bs2:BS2Name. In the following examples, a prefixed DO: represents the shell prompt which is followed by entries to the shell. Lines between the shell prompts are the outputs from the commands concerned. The procedure proc is included as an example: /BEGIN-PROCEDURE PAR=YES(PROC-PAR=(&CMD='STA',&CMDPAR='L')) / / WRITE-TEXT T='-----> ''&CMD &CMDPAR''' / &CMD &CMDPAR / SKIP-COMMAND TO-LABEL=OK / / SET-JOB-STEP / MOD-JV JV-CONTENTS=#BS2DOJV,/ SET-VALUE=C'Command ''&CMD &CMDPAR'' failed' / SKIP-COMMAND TO-LABEL=ERR / /.ERR REMARK / WRITE-TEXT T='-----> DOING EXIT-PROCEDURE ERROR=YES' / EXIT-PROCEDURE ERROR=YES / /.OK REMARK / WRITE-TEXT T='-----> DOING EXIT-PROCEDURE ERROR=NO' / EXIT-PROCEDURE ERROR=NO / END-PROCEDURE 186 U22794-J-Z125-6-76 Example 1 Procedure proc in POSIX, simple evaluation of the termination status DO: bs2do proc % JMS0066 JOB ODO492CACCEPTED ON 04-04-23 AT 11:28, TSN=57EE DO: echo $? 0 Example 2 Procedure proc in BS2000 file, SYSOUT is output in POSIX DO: bs2do -o example2.out bs2:proc % JMS0066 JOB ODO494CACCEPTED ON 04-04-23 AT 11:29, TSN=57EG DO: cat example2.out /CREATE-JV JV=#BS2DOJV /SET-JOB-STEP /MODIFY-JV JV=#BS2DOJV,SET-VALUE=C' ' /SET-JOB-STEP /CALL-PROC FROM-FILE=proc,LOGGING=NO -----> 'STA L' NAME TSN TYPE PRI CPU-USED CPU-MAX ACCOUNT# DO494 57EG 2 BATCH 9 220 0.6044 32000 1 RLOGIN 57C7 2 DIALOG 0 210 14.3916 9999 1 % SPS0171 NO LOCAL SPOOLOUT JOB PRESENT % SPS0420 RSO WARNING : SOME RSO PRINT-JOBS CANNOT BE DISPLAYED % SCP1095 DPRINTSV WARNING : SOME DPRINT PRINT-JOBS CANNOT BE .. -----> DOING EXIT-PROCEDURE ERROR=NO /SKIP-COMMANDS TO-LABEL=NOERR /.NOERR REMARK /SYSFILE SYSOUT=*DUMMY Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2do U22794-J-Z125-6-76 187 bs2do Example 3 Procedure proc in BS2000 PLAM library, erroneous procedure parameter DO: bs2cp proc 'bs2:BS2LIB(PROC,J)' # copy proc in PLAM library DO: bs2do -o example3.out bs2:\(BS2LIB,PROC\) "CMDPAR='x x'" % JMS0066 JOB 'DO501' ACCEPTED ON 04-04-23 AT 12:51, TSN = 57EN BS2DOJV: Command 'STA x x' failed DO:echo $? 1 DO: cat example3.out /CREATE-JV JV=#BS2DOJV /SET-JOB-STEP /MODIFY-JV JV=#BS2DOJV,SET-VALUE=C' ' /SET-JOB-STEP /CALL-PROC FROM-FILE=(BS2LIB,PROC),PROC-PAR=(CMDPAR='x x'),LOGGING= .. -----> 'STA x x' % EXC0898 INVALID OPERAND IN COMMAND. COMMAND REJECTED % CMD0205 ERROR IN PRECEDING COMMAND OR PROGRAM AND PROCEDURE .. -----> DOING EXIT-PROCEDURE ERROR=YES % CMD0205 ERROR IN PRECEDING COMMAND OR PROGRAM AND PROCEDURE .. /SET-JOB-STEP /SKIP-COMMANDS TO-LABEL=ERROR /.ERROR REMARK /SYSFILE SYSOUT=*DUMMY Example 4 Procedure proc in POSIX, erroneous procedure parameter, redirection of stderr DO: bs2do proc "CMD='STA P',CMDPAR=',TYPE=x " 2>example4.err DO: echo $? 1 DO: cat example4.err % JMS0066 JOB 'DO620' ACCEPTED ON 04-04-23 AT 15:43, TSN = 57H1 BS2DOJV: Command 'STA P ,TYPE=x' failed 188 U22794-J-Z125-6-76 bs2file set BS2000 file attributes (BS2000) bs2file defines the BS2000 file attributes of the file which is to be transferred. bs2file is mapped to the BS2000 FILE command. Syntax bs2file[Ë-h]Ëfile,operand_list -h Prints out the command syntax with an explanation of the options. 7. Juli 2009 Stand 11:58.27 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2file file Fully qualified file name in BS2000. The file attributes of this file are defined and used in the associated bs2cp command. Specifying "\*" ("\" is used for quoting) instead of a file name indicates that the settings in the bs2file command are valid for all files of the next bs2cp command. The file attributes then apply to the file(s) specified in the bs2cp command. If a fully qualified file name is specified, the bs2file entry only loses its validity if the file attributes are successfully analyzed in a bs2cp call when the file names are identical. If an asterisk (*) is specified, the bs2file entry loses its validity when the bs2cp command terminates. operand_list List of file attributes. The format of the operand_list must correspond to the format of the FILE command (BS2000). You may not use the operand "LINK=" in the FILE command. Hint If you issue multiple bs2file commands for a file then only the last attributes to be specified are valid. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 In the case of ISAM files, only the values KEYPOS=5 and KEYLEN=8 are supported for the key position and key length respectively. Error Error messages of the FILE command Example The BS2000 file doccopy is to be set up as a PAM file. $ bs2file doccopy,fcbtype=pam See also bs2cp, ftyp U22794-J-Z125-6-76 189 bs2lp bs2lp send files to a printer (BS2000) Print jobs are sent to the BS2000 spool via the PRNT macro. No ID is allocated for the print job. Management of the print job is only possible using the BS2000 spool. Syntax bs2lp[Ëoption]...[Ëfile] ... option -c This option is always set implicitly. The specified file is copied and the copies are printed. -d Output medium. You can specify a printer name or a pool name (printer class name). The environment variables LPDEST and PRINTER are not supported. -ncopies Use this option to specify the number of times the file is to be printed. The largest supported value for copies is 255, the smallest is 1. -ncopies not specified: A value of 1 is assumed for the number of copies. -ttitle (t - title) title will be printed in the header of the printout. -m, -o, -s, -w Ignored. file Name of the file which is to be printed. You can also enter more than one file. These files are then printed in the order in which they are specified when the command is called. You must specify any options which you only wish to apply to one file before entering the name of the file in question. file not specified: bs2lp reads from the standard input. Mode of operation The POSIX file is copied as a temporary SAM file, i.e. the ERASE operand is always implicitly set when SPOOL is called. 190 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdob.doc bs2lp Specifying additional operands for print jobs All keyword operands of the PRNT macro can be implicitly specified through the .lprc file which is searched for in the current HOME directory. At least one PRNT operand must be fully defined for each line. A line may contain more than one operand if these are separated by commas.The entries in the .lprc file are transferred to PRNT without checking. 7. Juli 2009 Stand 11:58.27 Example .lprc file: FORM=STD LINES=80 ROT=90, CHARS=R01 You cannot simultaneously specify an operand and an option which is mapped to this operand. Option mapping: – the option -d is mapped to the BS2000 operand DEST – the option -n is mapped to the BS2000 operand COPIES – the option -t is mapped to the BS2000 operand TEXT. Error bs2lp: ERROR: No (or empty) input files Exit status 0, if spool jobs were started successfully. Example The command bs2lp -n2 file and the entries in the .lprc file described above result in the following spool call for BS2000: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 PRNT file, COPIES=2,FORM=STD.LINES=80,ROT=90,CHARS=R01 U22794-J-Z125-6-76 191 bs2pkey bs2pkey set pkeys (BS2000) You can set the P keys [P3] and [P4] as follows by calling the command bs2pkey [P3] with @@c ([CTRL][C]) [P4] with @@d ([CTRL][D]) This command has no options. Syntax bs2pkey The program is called either in the POSIX shell (with no options) or can be included in the file /etc/profile. The program is then activated every time the shell is called. 192 U22794-J-Z125-6-76 cal print calendar cal writes a calendar on the standard output. Syntax cal[[Ëmonth]Ëyear] No argument specified: cal prints the calendar for the current month. 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cal month cal prints the calendar for the specified month. The possible values for month are 1 to 12. If you specify a value for month, you must also specify a value for year. month not specified: cal prints the calendar for the entire year. year The calendar for the specified year is printed. The possible values for year are 1 to 9999. Please note that cal 10, for example, refers to 10 A.D., not 2010. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 i If you call cal using the argument 1752 or the arguments 9 1752, the output for September is shorter than usual. This is because cal allows for an adjustment of 11 days which took place in that month in 1752. Exit status The exit status is non-zero if the values specified for year or month lie outside the permissible range. Error Bad argument [ for month | for year ] The values you have specified for year or month are not within the permissible range. Variable TZ Determine the timezone used to calculate the value for the current month. Locale The following environment variables affect the execution of cal: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. U22794-J-Z125-6-76 193 cal LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. Example LC_TIME Determine the format and contents of the calendar. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Print the calendar for Januar 2009 in the Locale C: $ cal 1 2009 January 2009 Su Mo Tu We Th Fr 1 2 4 5 6 7 8 9 11 12 13 14 15 16 18 19 20 21 22 23 25 26 27 28 29 30 194 Sa 3 10 17 24 31 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cancel cancel cancel line printer requests You can use cancel to abort or cancel any of the print jobs that you submitted with the lp command. i Nonprivileged users can abort or cancel only print jobs submitted under their own login names. Information on print jobs is displayed by the lpstat command. Syntax Format 1: cancel[Ëjobno...]Ëprinter... Format 2: cancelËjobno...Ë[printer...] You must specify a value for at least one of the operands. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 jobno In jobno you specify the job number of a print job. The job number is the number that is reported on standard output when you submit a print job with the lp command. You may specify more than one job number, using blanks to separate them. If necessary, you can obtain a list of all pending print jobs with the lpstat command. Nonprivileged users can request information only about the status of print jobs submitted under their own login names. cancel issues a message on standard output to tell you which print jobs have been cancelled or aborted. printer In printer you specify the name of a RSO printer or a printer group. You may specify more than one name. Any print job currently running on printer is aborted, and the printer is freed for the next job. cancel issues a message on standard output to tell you which print jobs have been aborted. You can use lpstat to find out which printers currently have jobs of the own userid running on them. Error cancel: printer "G005" was not busy None of the printers in the printer group that you specified, G005 in this case, had a print job running on it. When you specify a printer group name, you can only terminate a job that is currently printing on a printer in the named group. You cannot use this method to cancel print jobs that have been submitted but are still waiting to be executed. To cancel queued print jobs, you must specify the job number. cancel: request "TSN-AB35" non existent The job number you specified in the cancel call, TSN-AB35 in this case, is not the number of an existing print job. Use lpstat to obtain a list of all currently executing and pending print jobs. U22794-J-Z125-6-76 195 cancel UX:cancel: WARNING: "XY" is not a request id or a printer TO FIX: Cancel requests by id or by name of printer where printing. When you called cancel, you specified an argument XY which is neither a job number nor the name of a printer group. Locale The following environment variables affect the execution of cancel: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the default locale will be used. If any of the variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 You inadvertently submit the same print job twice, so you want to cancel the second one. $ lp test test request id is TSN-6J1V (test) request id is TSN-6J1W (test) $ cancel tsn-6j1w request “TSN-6J1W“ cancelled Example 2 Your system has two printer groups, G001 and G002, each of which consists of one printer. The job currently executing on printer group G001 is to be aborted: $ cancel G001 request "TSN-1234" cancelled The job number of the terminated print job was TSN-1234. The print jobs with job numbers TSN-9WJ7 and TSN-9WAS are to be cancelled: $ cancel TSN-9WJ7 TSN-9WAS request "TSN-9WJ7" cancelled request "TSN-9WAS" cancelled See also 196 lp, lpstat [11] U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command cat cat concatenate and print files The cat command reads files in sequence and writes them to standard output. cat has no effect on the sequence and format of the characters in the files. If you name more than one file when calling cat, these files are output sequentially in the specified order. If you do not name a file, cat reads from standard input. Syntax cat[Ë-s][Ë-u][Ëfile]... No option specified: Output is buffered in BUFSIZ-byte blocks. The value of BUFSIZ is governed by the machine you are working on. It is defined in the file /usr/include/stdio.h and may be 8192 bytes. If the files named on the command line do not exist, cat tells you that it cannot open them. -s Messages reporting that files do not exist are suppressed. -u Output without buffering, one byte at a time. file Name of the file that is to be printed. You may specify more than one file. If you use a dash as the name for file, cat reads from standard input. file not specified: cat reads from standard input. ! Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Error Caution! Redirecting the output of cat to one of the files being read will result in the loss of that file’s original contents. In the following command, for example, the contents of file1 are lost: cat file1 file2 file3 > file1 cat >out_file out_file: cannot create You have no write permission for the output file out_file or for the directory which contains out_file. cat in_file cat: cannot open in_file: Permission denied You have no read permission for the input file in_file. Locale The following environment variables affect the execution of cat: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. U22794-J-Z125-6-76 197 cat Built-in sh command LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_CTYPE governs character classes, character conversion (shifting) and the behavior of character classes in regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Concatenate and redirect the output of two files: $ echo Monday Tuesday Wednesday >file1 $ echo Thursday Friday Saturday >file2 $ cat file1 file2 > file3 $ cat file3 Monday Tuesday Wednesday Thursday Friday Saturday Example 2 Display the contents of file1 $ cat file1 In Xanadu did Kubla Khan A stately pleasure dome decree: Where Alph, the sacred river, ran Now write two lines of text into file2. Terminate input with [END] or @@d depending on the terminal type used. $ cat > file2 Through caverns measureless to man Down to a sunless sea. Now move the contents of file1 and file2 to file3, add two lines from standard input, and then print the contents of file3. Terminate input with [END] or @@d depending on the terminal type used. $ cat file1 file2 - > file3 For he on honey dew hath fed And drunk the milk of paradise. $ cat file3 In Xanadu did Kubla Khan A stately pleasure dome decree: Where Alph, the sacred river, ran Through caverns measureless to man Down to a sunless sea. For he on honey dew hath fed And drunk the milk of paradise. See also 198 cp, pr U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command cd cd change working directory The built-in cd command in the POSIX shell sh makes the specified directory your current working directory. The cd command is rejected in a restricted shell. Syntax Format 1: cd[Ëdirectory] Format 2: cdËFormat 3: cdËoldËnew Format 1 Change directory using CDPATH cd[Ëdirectory] directory Name of the directory that is to become your current working directory. You must have execute permission for this directory. If you specify a relative or absolute path name for directory, you must have execute permission for all the directories which make up this path name. If the name of the specified directory begins with one of the following characters, the command looks for the directory without reference to the CDPATH environment variable (see POSIX environment variables): / means that the search begins in the root directory. ./ means that the search begins in the current directory. ../ means that the search begins in the parent directory. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If the name of the specified directory does not begin with any of the above characters, cd evaluates the CDPATH environment variable: – If the CDPATH variable has not been defined or is null, cd looks for the specified directory relative to the current working directory. – If the CDPATH variable has been assigned a value, cd looks for the specified directory sequentially in the directories whose paths are defined in the CDPATH variable. On finding the directory, cd writes the absolute path name of this directory on standard output before switching to it. directory not specified: The cd command puts you in your home directory. The home directory is identical to the login directory unless there is a different path name assigned to the shell variable HOME. Format 2 cdË- Specifying the - as an operand has the same effect as the command cd “$OLDPWD“ && pwd which changes to the last active directory and writes its name. U22794-J-Z125-6-76 199 cd Format 3 Built-in sh command Change directory with text substitution cdËoldËnew cd substitutes the string new for the string old in the current directory name (PWD) and tries to change to this new directory. Error sh: file: not found The specified directory does not exist. You can verify this with ls -l. sh: file: not a directory Your argument is not a directory. This can also be verified with ls -l. file: permission denied You do not have execute permission for the specified directory. If you have specified a relative or absolute path name for directory, you do not have execute permission for one of the directories which make up this path name. rsh: cd: restricted cd has been rejected because you are working in a restricted shell. Variable HOME contains the absolute path name of your home directory. CDPATH You can assign to CDPATH the absolute path names of directories that cd is to search. By default this variable is undefined. OLDPWD Path name of the previous directory used by cd -. PWD Path name of the current directory. This name is set by cd following the change to this directory. Locale 200 The following environment variables affect the execution of cd: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command cd LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 The following entry makes the subdirectory dates the current directory: $ cd dates $ pwd /home/rose/dates Example 2 User rose has redefined the CDPATH environment variable. She now wishes to change to her subdirectory usr, but with the following commands ends up in the directory /usr instead: $ echo $CDPATH /:/home/rose/dates:. $ pwd /home/rose $ ls -l drwx--x--x 2 ROSE drwx--x--x 2 ROSE -rw------- 1 ROSE . . . $ cd usr $ pwd /usr The usr directory is first looked for in the directories whose path names are assigned to the CDPATH variable. In this case, CDPATH contains a / for the root directory as the first path name. The current directory is the last to be searched by cd. © cognitas GmbH 2001-2007 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 144 Feb 28 12:32 usr 192 Feb 28 11:51 dates 11734 Mar 7 16:22 tests User rose can prevent cd from evaluating the CDPATH environment variable by formulating the command in the following way: $ cd ./usr $ pwd /home/rose/usr See also pwd chdir() [4] U22794-J-Z125-6-76 201 chgrp chgrp Built-in sh command change file group ownership chgrp changes the user group for a file or a directory. You can only use it if you are the file/directory owner or the POSIX administrator. Only the POSIX administrator is permitted to change the user group for each file as he or she wishes. There is an operating system configuration option _POSIX_CHOWN_RESTRICTED which can be used to place a restriction on the groups to which users without POSIX administrator privileges can reassign their files. If this option is in effect, as an ordinary user you can assign your files to another group only if – you are listed in the /etc/group file as a member of the new group (see page 203), and – you currently belong to the new group, which means that before calling chgrp you must change to the new user group with the newgrp command (see section “newgrp change to a new group” on page 568 and the example on page 203). If chgrp is called by a user who does not posses POSIX administrator permissions then all the s-bits (set-user-ID and set-group-ID, see section “chmod change file modes” on page 204) set for the specified files are reset. Syntax chgrp[Ë-h][Ë-R]ËgidËfileË... -h If file is a symbolic link, chgrp changes the group ID of the symbolic link itself. Without this option, the group ID of the file referenced by the symbolic link is changed. -R (recursive) chgrp recursively descends through the specified directories, changing the group ID as it proceeds and traversing any symbolic links that it encounters. gid (group id). New group name or new group ID. gid must appear in /etc/group. file Name of the file or directory for which the user group is to be redefined. You can also list any number of files and/or directories. Error file: Not super-user You are not permitted to change the user group of the specified file, since you are not the owner of the file or have not been entered as a member of the specified group or do not currently belong to the group. Only the POSIX administrator is authorized to redefine the group for all files. chgrp: unknown group: gid The group name you have specified for gid is not in the /etc/group file. 202 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command File chgrp /etc/group The group file /etc/group contains a list of all existing user groups. Each line of this file consists of four colon-separated fields: groupname:groupid:user,user... Only the POSIX administrator is permitted to create new user groups and to enter new group members. Locale The following environment variables affect the execution of chgrp: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example Determine the location of message catalogs for the processing of LC_MESSAGES. You are currently working under the login name cindy; this name is entered in the /etc/group file as a member of the user groups ag and prog. At present, you belong to the user group ag as is evident from the fact that the name ag is entered for "group" when you create new files: $ >file $ ls -l file -rw------1 CINDY ag 0 Feb 17 15:48 file You now wish to change the user group for file; the new group is to be prog. To do this, you first use the newgrp command to switch to the prog group and then change the group for file with chgrp. $ newgrp prog $ chgrp prog file $ ls -l file -rw------1 CINDY See also prog 0 Feb 17 15:48 file chmod, chown, id, newgrp chown() [4] U22794-J-Z125-6-76 203 chmod Built-in sh command chmod change file modes chmod is used to change the permissions of a file (its protection mode). Only the owner or the POSIX administrator is authorized to change the permissions of a file. A file’s set-group-id bit can be set only by a user whose current group ID is the same as the file’s group ID (see section “chgrp change file group ownership” on page 202 and section “newgrp change to a new group” on page 568). Syntax chmodË[-R]ËmodeËfileË... -R (recursive) chmod recursively descends through the specified directories, changing the mode for each file it encounters. mode In mode you specify how the permissions for one or more named files are to be changed. There are two forms of mode specification: – symbolic – absolute file Name of the file for which you wish to define or alter the permissions. file may also be a directory. Multiple names are also allowed. Symbolic form [who]op[permission][,[who]op[permission]]... who In who you say who the file permissions apply to. The choices for who are: u for the owner (user) g for the group o for others a for ugo, i.e. all users. or any combination of the letters u, g, o. who not specified: who defaults to ugo, i.e. all users. The permissions for ugo are set with allowance for the bits in the file-creation mode mask (see umask). 204 U22794-J-Z125-6-76 chmod op In op you specify whether permissions are to be granted, left unchanged, or revoked. The choices for op are: + to add (grant) permissions, – to take away (revoke) permissions, = to assign permissions absolutely, i.e. only the listed permissions are granted, all others are revoked. permission In permission you specify which permission(s) you wish to grant or revoke. The choices for permission are: r for read permission w for write permission x (x - execute) for execute permission or for permission to browse files and directories. X for execute permission or for permission to search in a file, if at least one x bit is set, or in directories. If the file is not a directory, or if no x bit has been set for the file, this option is ignored. s for the set-user-ID or set-group-ID bit. Entering s in a chmod command is only useful in conjunction with u, g, or ug (if who is not specified, it defaults to ug). Set-user-ID and set-group-ID bits only apply to executable binary files (not to shell scripts) (see The s bits). t for sticky bit (t bit). Only the POSIX administrator is able to set the sticky bit. Attempts by nonprivileged users to set the sticky bit are ignored. Entering t in a chmod command is useful only in combination with u or a or if who is not defined. A set sticky bit only applies to executable files (see The sticky bit). If you change the mode of a file which has the sticky bit set, the sticky bit is automatically cleared. l (lock) for mandatory locking of files, directories or records, referring to a file’s ability to have its reading or writing permissions locked while a program is accessing it. file’s l bit can be set only if its group execute permission is not set and its set-group-id bit is set. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command Thus the following examples are not correct and would result in error messages: chmod g+x,+l file chmod g+s,+l file U22794-J-Z125-6-76 205 chmod Built-in sh command u Use the permissions of the current owner. g Use the permissions of the current group. o Use the permissions of the current others mode. permission not specified: This is only useful in combination with the = operator; all permissions are then revoked for the who in question. As indicated above, you can specify several "who-op-permission" arguments in a row, provided they are separated by commas as follows: chmod g-w,o-rw file The string you specify for mode is processed by chmod from left to right. For instance, a-w,u+w grants write permission to the owner, revoking it for all others. Absolute form An absolute mode is a three or four digit octal number. The admissible octal values are obtained by logically ORing (in binary) the octal modes shown below. The effect is the same as adding the modes in octal or decimal. A leading zero (neither the s bit nor the sticky bit set) may be omitted. The specified permissions are granted; all other permissions are revoked. 206 4000 Set user ID on execution 20#0 Set group ID on execution if # is 7, 5, 3 or 1.Set mandatory locking if # is 6, 4, 2 or 0.The value of # is ignored if file is a directory. In this case you can only use the symbolic form for mode. 1000 sticky bit (t bit) 0400 read permission for owner 0200 write permission for owner 0100 execute permission (or directory search permission) for owner 0040 read permission for group 0020 write permission for group 0010 execute permission (or directory search permission) for group 0004 read permission for others 0002 write permission for others 0001 execute permission (or directory search permission) for others U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command chmod Example To grant read, write, and execute permission to the owner and read and execute permission to the group, you would enter a value of 750 for mode: 400 + 200 + 100 + 40 + 10 = 750 The file then has the permissions rwxr-x--The s bit When an executable program which has the set-user-ID bit set is called, the effective user ID of the associated process is the same as the user ID of the owner of the file (and not that of the caller). In other words, the process runs under the user ID of the program owner and can therefore also access files for which the caller of the program does not have explicit access permission. The real user ID of the process remains that of the program caller. If the set-group-ID bit is set, the effective group ID of the process is the same as the group ID of the program owner. This means that the process runs under the group ID of the program owner. The real group ID of the process remains that of the program caller. The s bits are only useful for executable binary files (executable programs) and not for shell scripts. Although chmod can be used to set the s bits for files that contain a shell script, the setting will essentially have no effect. When changes are made to a file, the s bits are reset for security reasons. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 i If the POSIX administrator sets the s bit for a program which he or she owns, all users who can call the program are thereby authorized to carry out any operations that the POSIX administrator is allowed to perform using the program. Hence the POSIX administrator should not set the s bit unless it is certain that security will not be compromised, leading to data loss for example. Example of an s bit application One example of an s bit application is the mailx command. Messages sent with mailx to user USER1 are written to the file /var/mail/USER1. This file belongs to the group MAIL, and its owner is USER1. Both group and owner have read and write permission; no other users have any permissions for the file: -rw-rw---- USER1 MAIL /var/mail/USER1 Thus ordinarily a user from a different group (USER2, for example) would be unable to write messages to this file. However, since the mailx command has the s bit set for the MAIL group, after calling mailx USER2 temporarily becomes an effective member of the MAIL group and thus has write permission for /var/mail/USER1. U22794-J-Z125-6-76 207 chmod Built-in sh command The sticky bit (t bit) Only the POSIX administrator is able to set the sticky bit (t bit). Attempts by non-privileged users to set the sticky bit are ignored. The sticky bit only has an effect on directories and executable files. It is possible to use chmod to set it on other files, but it will then have no effect. If the sticky bit is set on an executable file, it is possible to some extent to save on the overhead usually involved in reading a program in from the disk file again every time the program is started. If a directory is writable and has the sticky bit set, files within the directory cannot be removed, renamed or linked to unless one or more of the following conditions apply: – the file belongs to the user – the directory belongs to the user – the user has write permission for the file – the user is a privileged user In the output of the ls -l command, the sticky bit if set appears in the last position of the listed permissions. If the x bit has simultaneously been set for "other users", a t appears; if not, a T. The l bit The lockf() function allows a program to place a lock on a file which it is accessing. If this file has its l bit set, the function call results in mandatory locking of the file (see lockf() [4]). Error chmod: ERROR: Invalid mode You have defined an illegal set of permissions for chmod. chmod: WARNING: Locking not permitted on file, a group executable file Files with group execute permission cannot also have the l bit set. chmod: WARNING: Execute permission required for set-ID on execution for file In order to turn on a file’s set-user-ID bit you need to have execute permission for the file. Locale 208 The following environment variables affect the execution of chmod: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. U22794-J-Z125-6-76 LC_CTYPE Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 chmod Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command Determine the location of message catalogs for the processing of LC_MESSAGES. The following examples all refer to a file with the permissions rw-------. The first two columns of the table contain possible mode arguments; the last column shows the result of a chmod call using these arguments. Symbolic form Absolute form Result u-w 400 r-------- -w 400 r-------- go+r 644 rw-r--r-- go=r 644 rw-r--r-- go+rw 666 rw-rw-rw- =rw 666 rw-rw-rw- +rx 755 rwxr-xr-x =r 444 r--r--r-- ug=rw,o=r 664 rw-rw-r-- u=rwx,g=rx,o= 750 rwxr-x--- +x,u+s 4711 rws--x--x +xt 1711 rwx--x--t The sticky bit (last example) can only be set by the POSIX administrator. Attempts by nonprivileged users to set the sticky bit are ignored. See also chgrp, ls, newgrp, umask chmod(), chown() [4] U22794-J-Z125-6-76 209 chown Built-in sh command chown change file ownership chown assigns a new owner to a file or a directory. Only the POSIX administrator may change the owners of a file as he or she wishes. In contrast, users who do not possess POSIX administrator permissions may only change the owners of their own files. If the operating system option _POSIX_CHOWN_RESTRICTED is in effect, even the owner of a file is prevented from changing the ownership of that file. If chown is called by a user without POSIX administrator permissions, the s-bit for owners, 4000, is reset. Syntax chown[Ë-h][Ë-R]Ëuid[:gid]ËfileË... -h If file is a symbolic link, chown changes the owner of the symbolic link. Without this option, the owner of the file referenced by the symbolic link is changed. -R (recursive) chown recursively descends through the specified directories, changing the file owner as it proceeds and traversing any symbolic links that it encounters. uid[:gid] Login name or user ID of the new owner. Optionally, the group ID may also be specified. file Name of the file that is to have a new owner. Directories and multiple file names are also allowed. Error chown: file: Not super-user You may not change the owner of the file file since you are not the owner of file or the _POSIX_CHOWN_RESTRICTED variable is set on your system. chown: Unknown user: newowner You have entered a user ID for newowner which is not entered in the user table. Locale 210 The following environment variables affect the execution of chown: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command chown LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. You are working as the POSIX administrator and want to change the owners of a file. You wish to assign the new owner MARK to the file text1 whose owner is CATHY. To do this, enter: # ls -l text1 -rw------1 CATHY # chown mark text1 # ls -l text1 -rw------1 MARK 2426 Feb 17 15:48 text1 ag 2426 Feb 17 15:48 text1 chgrp, chmod chown() [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also ag U22794-J-Z125-6-76 211 cksum cksum write file checksums and sizes The cksum utility calculates and writes to standard output a cyclic redundancy check (CRC) for each input file, and also writes to standard output the number of octets in each file. The CRC used is based on the polynomial used for CRC error checking in the referenced Ethernet standard. Syntax cksum[Ë-C][Ëfile...] options -C C calculates the CRC checksum in the same way as in previous versions. file A pathname of a file to be checked. The files may be of any type. file not specified: The standard input is used. You must use [END] or @@d to terminate input from standard input. Encoding The encoding for the CRC checksum is defined by the generating polynominal: G(x) = x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1 Mathematically, the CRC value corresponding to a given file is defined by the following procedure: 1. The n bits to be evaluated are considered to be the coefficients of a mod 2 polynomial M(x) of degree n -1. These n bits are the bits from the file, with the most significant bit being the most significant bit of the first octet of the file and the last bit being the least significant bit of the last octet, padded with zero bits (if necessary) to achieve an integral number of octets, followed by one or more octets representing the length of the file as a binary value, least significant octet first. The smallest number of octets capable of representing this integer is used. 2. M(x) is multiplied by x32 (that is, shifted left 32 bits) and divided by G(x) using mod 2 division, producing a remainder R(x) of degree Î31. 3. The coefficients of R(x) are considered to be a 32-bit sequence. 4. The bit sequence is complemented and the result is the CRC. 212 U22794-J-Z125-6-76 Locale 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cksum The following environment variables affect the execution of cksum: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Stdout Determine the location of message catalogs for the processing of LC_MESSAGES. For each file processed successfully, the cksum utility will write in the following format: "%u %d %s\n",, <# of octets>, If no file operand was specified, the pathname and its leading space will be omitted. Exit status 0 All files were processed successfully. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 >0 An error occurred. Hint cksum utility is typically used to quickly compare a suspect file against a trusted version of the same, such as to ensure that files transmitted over noisy media arrive intact. However, this comparison cannot be considered cryptographically secure. The chances of a damaged file producing the same CRC as the original are astronomically small; deliberate deception is difficult, but probably not impossible. Although input files to cksum can be any type, the results need not be what would be expected on character special device files or on file types not described by the XSH specification. Since this document does not specify the block size used when doing input, checksums of character special files need not process all of the data in those files. The algorithm is expressed in terms of a bitstream divided into octets. If a file is transmitted between two systems and undergoes any data transformation (such as moving 8-bit characters into 9-bit bytes), identical CRC values cannot be expected. Implementations performing such transformations may extend cksum to handle such situations. U22794-J-Z125-6-76 213 cksum Example Calculating the checksum for test, a file containing a list of the days of the week. $ cat test Monday Tuesday Wednesday Thursday Friday Saturday Sunday $ cksum test 1222782406 57 test See also 214 sum U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cmp cmp compare two files The cmp command does a comparison of two files byte by byte (character by character). If the files differ, cmp reports the differences on standard output. If the files are identical, cmp remains silent. Syntax cmp[Ë-l|Ë-s]Ëfile1Ëfile2 No option specified If the files are identical, cmp remains silent. If the files differ, cmp indicates the byte (character) and line number of the first difference that it detects between file1 and file2 as shown below: file1 file2 differ: char bytenumber, line linenumber -l All differences are reported in the following form: bytenumber byte(file1) byte(file2) bytenumber represents the displacement of the difference from the beginning of the file. The first byte of the file is assigned number 1, and blanks are counted. bytenumber is given in decimal notation. The byte columns show the bytes which differ between file1 and file2 and are in octal notation. An ASCII table of octal-coded values is provided in Tables and directories. If the files are identical, nothing is output. -s cmp remains silent. The exit status value is returned but not automatically displayed on the screen. You can enter the command echo $? to query the exit status. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file1Ëfile2 The names of the files that you wish to compare. – If you use a dash - as the name for file1, cmp reads from standard input and compares your input with file2. – If one of the two files ends before cmp can detect a difference, cmp reports that the end of the file has been reached in the shorter file by issuing the following message: cmp: EOF on file Exit status – If one character is missing in one of two otherwise identical files, cmp -l reports all following bytes as differences. This is due to the shift in character positions. – The first character of a file is assigned bytenumber 1, not 0. – Blanks and newline characters are included in the bytenumber count. 0 files identical 1 files differ 2 inaccessible file or missing argument U22794-J-Z125-6-76 215 cmp Error cmp: cannot open file You do not have read permission for one of the files, or one of the files does not exist. Locale The following environment variables affect the execution of cmp: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Compare two files and print the differing bytes (octal) and their bytenumber (decimal). $ echo 1 2 3 4 5 7 8 a >file1 $ echo 1 2 3 4 5 6 9 a >file2 $ cmp -l file1 file2 11 367 366 13 370 371 $ Example 2 The shell script delete.eq compares two files and deletes one of them if they are identical. if cmp -s $1 $2 then rm $2 fi When you call the script with $ delete.eq file1 file2 you pass file1 and file2 to it as positional operands. The -s option causes cmp to return the exit status. If the value of the exit status is 0 (=true), file2 is deleted; otherwise, it is retained. See also 216 comm, diff U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc comm comm select or reject lines common to two files comm compares two files in which the lines are sorted on the basis of the currently valid collating sequence. Sorting can be performed with the sort command (see page 688). Syntax comm[Ë-123]Ëfile1Ëfile2 No option specified comm produces three columns with the following meanings: Column 1 Column 2 lines which occur in file1 only lines which occur in file2 only lines which occur in both files Column 3 option -1 Column 1 is not output. -2 Column 2 is not output. -3 Column 3 is not output. -12 comm outputs all lines common to both files. -23 comm outputs all lines which only occur in file1. -13 comm outputs all lines which only occur in file2. -123 comm generates no output. file1Ëfile2 Names of the two sorted files which you want to compare. The comm command will not function properly unless both files have been sorted. If you use a dash as one of the names, comm reads from standard input. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Combinations of options 1, 2 and 3 are also permitted, e.g.: U22794-J-Z125-6-76 217 comm Locale The following environment variables affect the execution of comm: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the collating sequence comm expects to have been used when the input files were sorted. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH 218 Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 Example 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc comm The file books contains the titles of books and their authors. Each line contains the title of one book and the name of its author, with a space between them. You would now like to search the file books for a number of authors whose names you have listed in the file authors1. The contents of books and authors1 are as follows: books authors1 "Gormenghast" Peake "Buddenbrooks" Mann "Noddy" Blyton "Ulysses" Joyce Blyton Gogol Joyce Kafka Mann Tolstoy You can now proceed as follows: – Use awk to extract the authors from books. – Sort the authors in books using sort. – Redirect the output of sort to the new file authors2. – Compare the files authors1 and authors2 using comm -2. $ awk '{printf"%s\n",$2}' books| sort > authors2 The file authors2 contains the following: Blyton Joyce Mann Peake Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ comm -2 authors1 authors2 Blyton Gogol Joyce Kafka Mann Tolstoy All authors which are only in authors1 are output in column 1. Then come the contents of column 3, which lists all authors present in both files. See also cmp, diff, sort, uniq U22794-J-Z125-6-76 219 command Built-in sh command command execute a simple command command informs the shell that the arguments are to be executed as simple commands. The shell functions are not evaluated. command also provides information about how a command name is interpreted by the shell (see Format 2). Syntax Format 1: command [Ë-p]Ëcommand_name [Ëargument ...] Format 2: command [Ë-v |Ë-V]Ëcommand_name Format 1 command [Ë-p]Ëcommand_name [Ëargument ...] option -p The command search is performed using a default value for PATH which ensures that all standard commands can be found. command_name The name of a command or a special built-in command. argument One of the strings as an argument for command_name. Format 2 command[Ë-v |Ë-V]Ëcommand_name option -v A string is written to the standard output. This string specifies the path name or command which the shell uses to call command_name in the current shell environment. – Commands, regular built-in commands, command_names containing a slash as well as implementation-specific functions which are specified by the PATH variable are written as absolute path names. – Shell functions, special built-in commands and regular built-in commands which cannot be accessed via the definition in the PATH variable as well as reserved shell terms are specified as simple names. – An alias is written as a call line which represents the alias definition. – In other cases, no string is written to the output. The exit status specifies that the command could not be found. The standard output is formatted as follows: “%s\n”, 220 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command command -V A string is written to the standard output. This string specifies how the shell interprets the name in the command_name operand in the current shell environment. Although the format of the string is not specified, it nevertheless defines which of the following categories command_name belongs to. The associated information is also defined: – Commands, regular built-in commands and implementation-specific functions which are found via the PATH variable are identified as such. In this case the string contains the absolute path name. – Other shell functions are identified as functions. – Aliases are identified as aliases. The definitions are specified in the string. – Special built-in commands are identified as special built-in commands. – Regular built-in commands which cannot be accessed via the definition in the PATH variable are identified as regular built-in commands. (The term "regular" is optional.) – Reserved shell terms are identified as reserved shell terms. The standard output is formatted as follows: “%s\n”, command_name The name of a command or of a special built-in command. Field of application Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The command search sequence can be used to disable functions, regular built-in commands and the path search sequence. This is necessary so that functions which share the same name for a command are able to call this command (instead of a recursive function call). The default system path is available via getconf. Since under certain circumstances PATH must have been set before getconf is called, the following options are available: command -p getconf _CS_PATH Occasionally it can be desirable to suppress the properties of special built-in commands. For example: command exec > non_writable_file This input does not cause a non-interactive procedure to abort. The output status can be queried by the procedure. Return code 127 is used for command, env, nohup, time and xargs if an error occurs or if command_name could not be found. This enables applications to determine whether it was impossible to find a command or whether the command was terminated with an error. The value 127 was selected because it is not generally used for any other meaning. Low values are generally used for "normal error conditions". Values higher than 128 may be mistaken U22794-J-Z125-6-76 221 command Built-in sh command for termination resulting from signal reception. For similar reasons, the value 126 was selected to indicate that although the command was found, it could not be called. Many procedures generate informative error messages which differentiate between 126 and 127. This distinction between return codes 126 and 127 is based on experience of the Korn shell which handles these codes as follows: 127 is used if all attempts to execute the command exec fail with [ENOENT]; 126 is used if an attempt to execute exec fails for any other reason. Since with the options -v and -V the output for command is generated in accordance with the current shell environment, command is generally provided as a regular built-in shell command. If the call is issued in a subshell or a special run environment such as: (PATH=foo command -v) nohup command -v this does not always yield correct results. Thus, for example, in certain run environments most implementations are unable to recognize alias names, functions or special built-in commands if the call is made via the nohup or exec functions. Two types of regular built-in commands may be present in a system. Both are described separately under command. The description of a command search allows for the implementation of a default command as a regular built-in command provided that this is read at the correct position in a PATH search. Thus, for example, the result of command -v true may be the path name /bin/true or a similar path name. Other, implementation-specific commands which are not defined in this documentation may also occur as built-in commands. No path name is allocated to such commands. The output is identified as that of (regular) built-in commands. In no case can applications execute the command exec, use nohup, disable the output by means of another PATH etc. Locale The following environment variables affect the execution of command: LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_CTYPE Determines the internationalized environment for the interpretation of byte sequences as characters (e.g. single-byte characters as opposed to multibyte characters in arguments). LC_MESSAGES Determines the format and contents of error messages. The internationalized environment specified here is also valid for informative messages written to standard output. 222 U22794-J-Z125-6-76 command NLSPATH Determines the position of message catalogs for the processing of LC_MESSAGES. PATH Determines the search path used during the command search, except where a default value has been set with -p. Example 1 A version of cd is generated which outputs the current directory precisely once: 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command cd() { command cd “$@“ >/dev/null pwd } Example 2 A "safe shell procedure" is started in which the procedure cannot be influenced by the parent: IFS=‘ ‘ # The preceding value should be . # IFS is set to the default value. \unalias -a # All possible aliases are reset. # unalias is quoted to prevent the use of # any alias. unset -f command # The command may not be a user function. PATH=“$(command -p getconf _CS_PATH):$PATH“ # Introduce PATH prefix. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 # ... Provided that the access permissions for the directories called by PATH are set correctly, then at this point the procedure can make sure that the called commands actually correspond to the commands which are to be addressed. Great care is taken here since it is assumed that implementation-specific extensions may be present which permit user functions when called. Although this possibility is not described in this documentation, such an extension is perfectly possible. For example the variable ENV precedes the call to a procedure with a user-defined start procedure. Such a procedure might, for example, define functions which affect the application. See also sh, type U22794-J-Z125-6-76 223 compress compress compress files compress reduces the size of files using adaptive Lempel-Ziv coding: recurrent strings in the text are reduced to unique codes ranging from 9 to a maximum of 16 bits. If the calling process has the appropriate privileges, the owner, access permissions, and the dates of last access and modification of the specified files remain the same. Each specified file is replaced by a file with the same basename plus a .Z extension. The amount of compression obtained depends on the size of the input file, the value of bits (see option -b below), and the distribution of recurrent substrings. Typically, files containing only text or source code are reduced by 50-60%. Compression achieved with the LempelZiv approach is generally much better than that achieved with Huffman coding, and takes less time to compute. No compression is performed if – the input file is not a regular file (if it is a directory, for example) – there are other links to the input file – the input file already has a .Z extension – the .Z file to be created already exists, and compress is being executed in the background – no savings can be achieved by compression Files compressed with compress can be decompressed with uncompress. zcat produces uncompressed output on the standard output, but leaves the compressed file intact. Syntax Format 1: compress [Ë-fv][Ë-bËbits][Ëfile ...] Format 2: compress [Ë-cfv][Ë-bËbits][Ëfile] No option specified The specified files are compressed if storage space can be saved as a result. option -c Simply writes the output of compress to standard output without modifying or creating any files. Only one file is allowed with -c. -f (f - force) Forces compression even if no space savings will be achieved or the .Z file that will be created already exists. If the .Z file already exists it will be overwritten. -f not specified: compress prompts to verify whether an existing .Z file should be overwritten. No prompt is issued if compress is running in the background. -v (verbose) Displays the percentage reduction for each file compressed: file Compression: xx.xx% –– replaced with file.Z 224 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc compress -bËbits Sets the upper limit (in bits) for recurrent substring codes to bits. The value for bits must be between 9 and 16. Lowering the number of bits will result in larger, less compressed files. 7. Juli 2009 Stand 11:58.28 The bits parameter specified during compression is encoded within the compressed file, together with a magic number to ensure that it is impossible to further compress a file which is already compressed. -b not specified: The value of maxbits defaults to 16. Caution! Although compressed files are compatible between machines with large memory, the -bË12 option should be used for file transfer to architectures with a small process data space (64 Kbyte or less). ! file Name of the file to be compressed. You may specify more than one file. If you specify a hyphen (-) for one of the files, compress will read that file from standard input. file must not be a directory, and there must be no other links to it. The compressed file is assigned the name file.Z, and the named file is deleted after successful compression. file.Z has the same access permissions, access time and modification time as file. The maximum length of the name of file depends on the file system being used. The maximum allowable length is equal to the maximum file name length supported by the file system, minus 2 characters. This allows for the extension to file.Z. If this length is exceeded, file will not be compressed. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file not specified or specified as a hyphen (–): Data from standard input is written in compressed form to standard output. Exit status 0 Compression successful 1 Error 2 Compression of one or more files not performed, as it would have increased the size of the file. >2 Error U22794-J-Z125-6-76 225 compress Error file: filename too long to tack on .Z The name of the compressed file is too long. No compression takes place. file -- not a regular file: unchanged If the input file is not a regular file it is left uncompressed. file: -- has xx other links: unchanged The input file has xx other links; it is left uncompressed. file unchanged No savings can be achieved by compression. The input file remains uncompressed. The -f option can be used to force compression. Locale The following environment variables affect the execution of compress: LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_CTYPE Determines the internationalized environment for the interpretation of byte sequences as characters (e.g. single-byte characters as opposed to multibyte characters in arguments). LC_MESSAGES Determines the format and contents of error messages. NLSPATH Example Determines the position of message catalogs for the processing of LC_MESSAGES. The file films, which occupies 4862 bytes in uncompressed form, is to be compressed. $ ls -l total 10 -rw------- 1 FELIX group1 4862 Aug 19 09:27 films $ compress -v films compress: filme: 50.78% Compression -- replaced with films.Z $ ls -l total 6 -rw------- 1 FELIX group1 2393 Aug 19 09:27 films.Z See also 226 uncompress, zcat U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command cp cp copy files cp copies files. Copying means: the file is afterwards physically present in two locations. cp has four formats. The command copies – one file to another with a different name (Format 1) – one or more files to a different directory, with the copy retaining the same basename as the corresponding original (Format 2). – each file file in the file hierarchy to one of the target paths specified below (formats 3 and 4) Syntax Format 1: cp[Ë-fip]ËfileËcopyfile Format 2: cp[Ë-fip]ËfileË...Ëdirectory Format 3: cpË-R[Ë-fip]ËfileË...Ëdirectory Format 4: cpË-r[Ë-fip]ËfileË...Ëdirectory Format 1 Copy one file: cp[Ë-fip]ËfileËcopyfile -f If it is impossible to obtain a file descriptor for copyfile (step 3.a.ii.), then an attempt is made to call unlink() for copyfile. Processing is continued. -i (interactive) If the named copyfile already exists, cp will ask you to confirm whether this file may be overwritten. A y answer means that the copy operation should proceed. Any other answer prevents cp from overwriting copyfile. If the standard input is not a terminal, this option is ignored and no copying is performed. -p The following properties of all files are duplicated in the corresponding copyfile: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 1. The last time the data was changed and the time of the last access. If this procedure should fail for any reason then cp writes a message to the standard error output. 2. The user ID and group ID. If this procedure should fail for any reason then cp writes a message to the standard error output. 3. The bits for permissions as well as the bits S_ISUID and S_ISGID. If this procedure should fail for any reason then cp writes a message to the standard error output. If it is impossible to duplicate user ID or group ID then the bits for S_ISUID and S_ISGID are duplicated. The sequence for the duplication of the properties listed above is not defined. copyfile is not deleted if these properties cannot be retained. file Name of the original file. U22794-J-Z125-6-76 227 cp Built-in sh command copyfile Name of the copy file. If copyfile does not yet exist, a new file is created. Unless the -p option is used, the copy will have the same mode as the original file, and the user and group ID of the copy will be those of the user who called cp, but the time of last modification of the copy will be set to the time the copy was made. ! Caution! If a file named copyfile already exists and the -i option is not used, the existing file will be overwritten without confirmation, but its mode, owner, and group will be preserved. If copyfile is a link to a file, all links will be retained. The contents of copyfile will be overwritten with the contents of file. Format 2 Copy files to another directory cp[Ë-fip]ËfileË...Ëdirectory -fip see Format 1 file Name of the original file. You can give a list of names and thus copy several files at once. Each of the copies is assigned the same basic file name (basename) as the corresponding original. ! Caution! If there is a file in directory with the same basename as any original, and the -i option has not been set, the existing file will be overwritten without confirmation. directory Name of the directory in which the copies are to be placed. This must not be the directory in which the original files are located. Unless the -p option is set, the copies will have the same modes as the originals, and the user and group ID of the copies will be those of the user who called cp, but the time of last modification of each copy will be set to the time the copy was made. 228 U22794-J-Z125-6-76 Format 3 cp cpË-R[Ë-fip]ËfileË...Ëdirectory -fip see Format 1 -R copies data hierarchies. If the option -R is set then the following steps are performed: 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command i. copyfile is created with the same file type as file. ii. The permissions for copyfile are set to match those of file. Modification is subsequently performed via the user’s file creation mask provided that the option -p has not been specified. If this procedure should fail for any reason then cp writes a message to the standard error output. Processing of file is halted. However, other files may be processed as appropriate. fileËdirectory see Format 2 Format 4 cpË-r[Ë-fip]ËfileË...Ëdirectory -fip see Format 1 -r Copies file hierarchies. The way in which special files are handled is implementationdependent. If option -r is set then the way in which special files are handled is implementationdependent. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 fileËdirectory see Format 2 Procedure If directory already exists and is actually a directory, then the name of the target path for the individual files in the file hierarchy consists of a string formed by directory, a slash and the relative path name of the file corresponding to the directory which contains file. If directory does not yet exist and two operands are specified, then the name of the corresponding target path for file is the directory directory. The name of the corresponding target path for all other files in the file hierarchy consists of directory, a slash and the relative path name of the file corresponding to file. An error occurs if directory does not exist and more than two operands are specified. An error also occurs if directory exists and is a file type as defined in the XSH specification but is not a directory. U22794-J-Z125-6-76 229 cp Built-in sh command In the following description file is the file to be copied irrespective of whether it is specified via an operand or whether it is specified in a file operand as a file in a file hierarchy. The term copyfile designates the file which is specified by the target path. The following steps are performed for each file: 1. If file and copyfile designate the same file, cp writes a message to the standard error output where required. Processing of file is halted. However, other files may be processed as appropriate. 2. If file is a directory then the following steps are performed: a) If neither the option -R nor the option -r is specified, cp writes a message to the standard error output. Processing of file is halted. However, other files may be processed as appropriate. b) If file is not specified as an operand, and if file is either "." or "..", then processing of file is halted. However, other files may be processed as appropriate. c) If copyfile/directory is present and is a file type which is not specified in the XSH specification then the system reaction will depend on the specific implementation. d) If copyfile/directory is present and is not a directory, then cp writes a message to the standard error output. Processing of file as well as of any other files which are subordinate to file in the file hierarchy is halted. However, other files may be processed as appropriate. e) If the directory copyfile/directory does not exist then it is created and assigned the access permissions which apply to file. Modification is subsequently performed via the user’s file creation mask, if the option -p has not been set, together with a bitwise OR operation with S_IRWXU. If copyfile cannot be created, cp writes a message to the standard error output. Processing of file is halted. However, other files may be processed as appropriate. It is not possible to predict whether or not cp will attempt to copy files to the file hierarchy corresponding to file. f) The files in the directory file are copied to the directory copyfile/directory. Steps 1 to 3 are followed for the files. g) If copyfile/directory have already been created then the access permissions are modified (if necessary) so that they are compatible with the access permissions for file. Modification is subsequently performed via the user’s file creation mask provided that the option -p has not been specified. h) cp does not process file any further. However, other files may be processed as appropriate. 230 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc Built-in sh command cp 3. If file is a regular file then the following steps are performed: 7. Juli 2009 Stand 11:58.28 a) If copyfile is present then the following steps are performed: i. If the option -i has been set then cp writes a prompt to the default standard output and reads a line from the standard input. If the input is not a confirmation then cp discontinues processing of file. However, other files may be processed as appropriate. ii. A file descriptor for copyfile is obtained by performing the steps specified in the function open() in accordance with the XSH specification. copyfile is used as the path argument and the bitwise, inclusive OR operation of O_WRONLY and O_TRUNC is used as the oflag argument. iii. If the attempt to obtain a file descriptor fails and if the option -f has been set then cp attempts to remove the file by performing the steps specified in the function unlink() in accordance with the XSH specification. copyfile is used as the path argument. If this attempt is successful then cp continues processing with step 3b. b) If copyfile is not present then file descriptor is obtained by performing the steps specified in the function open() in accordance with the XSH specification. copyfile is used as the path argument and the bitwise, inclusive OR operation of O_WRONLY and O_TRUNC is used as the oflag argument. The permissions for file are taken from the mode argument. c) If the attempt to obtain a file descriptor fails then cp writes a message to the standard error output. Processing of file is halted. However, other files may be processed as appropriate. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 d) The contents of file are written to the file descriptor. If write errors occur then cp writes a message to the standard error output and continues processing with step 3e. e) The file descriptor is terminated. f) Error cp halts processing of file. If a write error has occurred at step 3d then it is impossible to predict whether or not cp will continue to process further files. If no write error occurred in step 3d then cp will continue to process files. cp: Cannot access file The named file does not exist. cp: Cannot open file : Permission denied You have no read permission for file. cp: cannot create file You do not have write permission for the directory in which file is to be created, or the named directory does not exist. U22794-J-Z125-6-76 231 cp Built-in sh command cp: dir directory dir is a directory and cannot be copied (Format 1), or you have not set the -r option (Format 4). Locale The following environment variables affect the execution of cp: LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_COLLATE Ddetermines the internationalized environment for the behavior of ranges, equivalence classes and multicharacter collating elements used in the extended regular expressions defined for the affirmative response. LC_CTYPE Determines the internationalized environment for the interpretation of byte sequences as characters (e.g. single-byte characters as opposed to multibyte characters in arguments and input files) and the behavior of character classes used in the extended regular expressions defined for the affirmative response. LC_MESSAGES Determines the format and contents of error messages. NLSPATH Determines the position of message catalogs for the processing of LC_MESSAGES. Example 1 The file techlit is to be copied before it is changed. The copy is to be called tl and to be located in the same directory as techlit. $ cp techlit tl Example 2 All files from the current directory with names beginning with fil are to be copied into the directory /home/do/save, and their times of last modification are to be duplicated. $ cp -p fil* /home/do/save $ ls -l /home/do/save total 4 -rw------ 1 DOBER gr1 -rw------ 1 DOBER gr1 -rw------ 1 DOBER gr1 -rw------ 1 DOBER gr1 See also 232 37 97 116 381 Nov Apr Dec Feb 11 01 31 16 11:11 13:24 12:13 08:08 file1 file2 filei3 file4 chmod, ln, mv, rm U22794-J-Z125-6-76 cpio copy in and out The cpio command has three functions: – it copies one or more files into an archive file (Format 1) – it retrieves files from a previously created archive (Format 2) – it copies files into a directory (Format 3) 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cpio i The cpio command has been withdrawn from the XG4 standard and replaced by the command pax. Consequently, only the pax command should be used in the future, since cpio is now supported only for compatibility reasons. Syntax Format 1: cpioË-o[Bacv][Ë-DËarchive] Format 2: cpioË-i[Bcdmrtuvf][Ë-DËarchive][Ëpattern...] Format 3: cpioË-p[adlmruv]Ëdir Only the three main options -o, -i and -p are detailed in the descriptions of the various formats shown above. The remaining options are listed in section “Modifiers and single options” on page 235. The various modifiers that can be used with each format are indicated in the format descriptions. Format 1 Copy files out cpioË-o[Bacv][Ë-DËarchive] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Modifiers Bacv Single option -DËarchive -o (out) cpio reads a list of pathnames of plain files from standard input and copies these files along with some status information in a special archive format to standard output or to the archive specified with the single option -D. The archive format is the same as the one created with the command pax -x cpio, where output is padded to a 512-byte boundary. The number of 512-byte blocks copied is written by cpio to standard error. U22794-J-Z125-6-76 233 cpio Format 2 Copy files in cpioË-i[Bcdmrtuvf][Ë-DËarchive][Ëpattern...] Modifiers Bcdmrtuvf Single option -DËarchive -i (in) cpio reads from standard input or the archive specified with the single option -D, which is assumed to be the product of a previous cpio -o, and extracts from it only those files with names that match pattern (see below). The extracted files are copied into the current directory tree in accordance with the specified options. The extracted files are given the same permissions as the files copied out with cpio -o. The user ID and group ID are those of the user calling cpio - i. It is only when the system administrator calls cpio - i that the extracted files retain the same user or group ID as the files copied out with cpio -o. Only the system administrator can extract special files. pattern pattern specifies the files to be selected from the archive. All shell metacharacters for file name generation can be used in defining pattern (see section “File name generation” on page 54). If pattern is not specified, all files are extracted from the archive. Format 3 Copy files to a directory cpioË-p[adlmruv]Ëdir Additional option adlmruv -p (pass) cpio reads a list of pathnames of plain files and copies these files to the named directory dir in accordance with the specified options. The number of 512-byte blocks copied by cpio is written to standard error. dir Name of the directory to which the files are to be copied. This directory must exist even if the -d modifier is specified. 234 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cpio Modifiers and single options The following modifiers may be specified in any order. Apart from the single option -D, they must all be directly appended to the main option -o,-i or -p without intervening blanks. a (access time) Resets access times of input files after they have been copied. If the modifier l is also specified, the access times of files to which links exist are not reset. B (block) Sets an I/O block size of 512 bytes. This option is only meaningful for special files with direct access (raw devices). This modifier must not be used in combination with the main option -p. c (compatible) cpio writes or reads header information in the archive in character format for compatibility reasons. d (directory) Subdirectories are automatically created as needed. f Only the files not matching pattern are copied. l (link) This option must only be used in combination with option -p. It results in the creation of links to the files, instead of the files being copied. m (modification time) The original file modification times are retained. This modifier has no effect on directories. The modifiers m and a must not be specified together, since they are mutually exclusive. r (rename) Allows files to be renamed interactively on extraction. cpio prompts for a new name for each file. If you respond with a blank line (by simply pressing the Enter key), the file will not be renamed. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If you respond with a dot (.), the file is copied without changing its name. Otherwise, the name of the file is changed to the text entered in response to the prompt. t (table of contents) cpio produces a table of contents of the archive. No files are copied. u (unconditional) Replaces an existing file with an extracted file even if the existing file has a more recent access date than the one being extracted. If the u modifier is not specified, the existing file is not overwritten. v (verbose) Causes cpio to display the names of the processed files. If v is used in conjunction with the modifier t, additional information on the processed files is displayed. U22794-J-Z125-6-76 235 cpio Ë-DËarchive archive names the archive file from which files are extracted or to which they are copied. This archive file is used instead of the standard input or standard output. Error Old format cannot support expanded types on file You have not specified the -c option. Due to compatibility reasons, cpio maintains the i-nodes of files to be copied in the old format, so i-nodes exceeding 64 Kbytes can only be processed if you have specified the -c option. directories are not being created You did not specify the -d option in Format 2. Locale The following environment variables affect the execution of cpio: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the internationalized environment for the behavior of ranges, equivalence classes and multicharacter collating elements in extended regular expressions for yes/no queries. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files) and the behavior of character classes in extended regular expressions for yes/no queries. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. 236 LC_TIME Determine the format and contents of the calendar. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 Example 1 All files in the current directory with names that begin with mb are to be copied out to an archive file named mailarchive: $ find . -name 'mb*' -print | cpio -o -D mailarchive 15776 blocks The find command searches the current directory for file names that begin with mb and writes all such file names to standard output, which is piped (|) to the standard input of cpio. cpio -o then reads the file names and copies the appropriate files along with status information to the archive file mailarchive (option -D). When it has finished, cpio writes the number of copied blocks to standard error. 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cpio Example 2 List the contents of the archive file named mailarchive. $ cpio -it -D mailarchive mbox mbox.new mbox.old 15776 blocks Example 3 The directory named dir.old is to be copied together with all its subdirectories. The duplicate directory is to be named dir.new: The cd command changes the current directory to dir.old. The command find then searches this directory and all other directories below it and writes the names of all the files that it find to standard output. Since the standard output of find is piped (|) to the standard input of cpio, cpio reads the file names and copies the files to the directory dir.new (which, in this example, is at the same level in the file tree as dir.old). Subdirectories are created as needed (-d), i.e. all subdirectories of dir.old are copied recursively. Since the -l option also specified here, instead of copying the files, links are created to the files where possible. See also ar, cat, echo, find, ls, pax, tar Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ cd dir.old $ find . -print | cpio -pdl ../dir.new U22794-J-Z125-6-76 237 crontab crontab schedule periodic background work crontab is used to have commands, shell scripts or executable programs executed regularly at specific times. You can use crontab to: – schedule command jobs (Format 1) – have scheduled jobs listed (Format 2) – delete scheduled jobs (Format 3) – edit scheduled jobs (Format 4) Jobs scheduled with crontab are retained even if the user who scheduled them closes the POSIX shell with exit or if the POSIX subsystem is shut down. There is no need to reschedule the jobs. Before the call The user ID must have a standard account number for rlogin access. This standard account number can be assigned using the ADD-USER, MODIFY-USER-ATTRIBUTES or ADDPOSIX-USER command. If the file /usr/lib/cron.d/cron.allow exists, you can only use crontab if your login name appears in it. If the file /usr/lib/cron.d/cron.allow does not exist, you can only use crontab if your login name does not appear in the file /usr/lib/cron.d/cron.deny. If neither /usr/lib/cron.d/cron.allow nor /usr/lib/cron.d/cron.deny exists, only the POSIX administrator is allowed to use crontab. If only an empty deny file exists, for example, everyone is allowed to use crontab. Only the POSIX administrator is allowed to create and modify the allow and deny files. Each line in these files contains precisely one login name. Before the crontab command is called, the POSIX administrator must have started up the cron daemon (/etc/init.d/cronËstart). ! Syntax Caution! If you inadvertently enter the crontab command with no arguments, do not attempt to get out with [CTRL][D]! This will cause all entries in your crontab file to be removed. Instead, use [DEL] to exit. Format 1: crontab[Ëfile] Format 2: crontabË-l[Ëlogin_name] Format 3: crontabË-r[Ëlogin_name] Format 4: crontabË-e[Ëlogin_name] 238 U22794-J-Z125-6-76 Format 1 Scheduling command jobs crontab[Ëfile] To schedule a command job with crontab you have to specify: – the command (or shell script or program) that is to be executed, and – the times at which it is to be executed (e.g. every Friday or every January 15). When you call crontab in the above format, crontab copies these specifications into your crontab file /var/spool/cron/crontabs/login_name. The /usr/sbin/cron process checks every minute whether there are commands in the crontab file which need to be executed, and if there are any, it has them executed. 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc crontab To execute the specified command, crontab invokes a new shell (sh) from your home directory. crontab supplies a default environment for every shell, defining HOME, LOGNAME, SHELL (/bin/sh), and PATH (:/bin:/usr/bin:/usr/lbin). If you wish to have your .profile executed, you must specify this explicitly in the crontab file. If neither the standard output nor the standard error output have been redirected for the commands in the crontab file, both the standard output and the standard error output will be sent to you by mailx. There can be at most one crontab file per login name. If the crontab file /var/spool/cron/crontabs/login_name does not exist, it is created when crontab is called. If it already exists, its contents are overwritten. In other words, if you wish to schedule additional command jobs with crontab, you should use the -e option. file Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Name of the file containing the commands and the times at which they are to be executed. file must be in the format described below (see “Format of a crontab file” on page 240). file not specified: crontab reads the text entered from the standard input. The text that you enter in this case must be in the format described below (see “Format of a crontab file” on page 240). Format 2 Listing scheduled jobs crontabË-l[Ëlogin_name] -l (list) crontab lists the contents of your crontab file /var/spool/cron/crontabs/login_name. If the file is not available, an error message is issued (see page 242). login_name If a login_name is specified, the crontab file of the corresponding user is listed. However, only the POSIX administrator is permitted to specify a login_name. U22794-J-Z125-6-76 239 crontab Format 3 Deleting scheduled jobs crontabË-r[Ëlogin_name] -r (remove) crontab deletes your crontab file /var/spool/cron/crontabs/login_name. login_name If a login_name is specified, the crontab file of the corresponding user is deleted. However, only the POSIX administrator is permitted to specify a login_name. Format 4 Editing scheduled jobs crontabË-e[Ëlogin_name] -e (edit) The -e option allows you to edit a copy of your crontab file or to create an empty file to edit (if crontab does not exist) and save this file as the current crontab file. The VISUAL environment variable determines which editor is called. If VISUAL is not defined, the EDITOR environment variable is checked, and if EDITOR is not defined, ed is invoked. login_name If a login_name is specified, the crontab file of the corresponding user is edited. However, only the POSIX administrator is permitted to specify a login_name. Format of a crontab file Your crontab file, or the text that you enter from standard input, (see Format 1) must be in the following format: Text comprising: – lines to define a command job, and – comment lines, if required. Blank lines are not permitted. Command job definition lines A line defining a command job consists of six fields separated by blanks or tabs. The fields contain the following information: 240 1 2 3 4 5 6 minute hour day of month month day of week command U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc crontab Fields 1 to 5 specify the times at which the command in field 6 is to be executed. Minute Range of values: 0-59 or pattern Hour Range of values: 0-23 or pattern Day of month Range of values: 1-31 or pattern Month Range of values: 1-12 or pattern Day of week Range of values: 0-6 (0=Sunday) or pattern Command Name of the command that is to be executed at the specified time. If your command needs to read data from standard input, you have to use the percent character %. Each % character in the command field that has not been escaped with a backslash (\) is interpreted as a newline character. The shell executes the content of the command field only up to the first unescaped percent or newline character; the remainder of the field is passed to the command as standard input (see example 3 on page 244). pattern may be: – an asterisk * (standing for all legal values) – a range described as number-number – a comma-separated list of legal numbers or ranges, e.g.: 1,3,5 or 1-3,5 Specifying the day Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Two fields are available for specifying the day; field 3 (day of month) and field 5 (day of week). If you enter a number, a range or a list in the third field as well in the the fifth field, both specifications are valid, independently of each other. For example, if your crontab file contains the line: 0 0 1,15 3 1 command then command will be executed on March 1 and March 15 as well as on every Monday in March. If you wish to specify the day in one field only, you must enter an asterisk in the second field. Thus if your crontab file contains the line: 0 0 * 3 1 command then command will be executed on every Monday in March. U22794-J-Z125-6-76 241 crontab Comment lines A comment line has the hash character # in column one and may be followed by any arbitrary text. You can use comment lines in the crontab file to explain the function of the command job or to arrange the job into sections for the sake of clarity. Please note that the input text that you pass to crontab can contain any number of comment lines but must not include any blank lines. Exit status Error 0: Successful execution of crontab. ≠0: An error occurred during crontab execution. crontab: you are not authorized to use cron. Sorry. See Before the call above. Format 1 crontab: can't open your crontab file. You have called crontab with the name of a file which does not exist or cannot be accessed. crontab: error in previous line; ... If any line of the input text that you pass to crontab is not in the correct format, crontab displays the relevant line followed by the above error message. The ellipses (...) shown here are replaced by a more detailed description of the error, e.g.: unexpected character found in line An illegal character was found in the line. number out of bounds A specified number is not in the permitted range. Format 2 crontab: can't open your crontab file. Your crontab file /var/spool/cron/crontabs/login_name does not exist and therefore cannot be read with crontab -l. File /usr/lib/cron.d/cron.allow List of login names with permission to use crontab. One login name is entered per line. /usr/lib/cron.d/cron.deny List of login names explicitly denied permission to use crontab. One login name is entered per line. /var/spool/cron/crontabs/login_name crontab file of the user identified by login_name. 242 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc crontab Variable Locale The following environment variables are used by crontab. VISUAL The VISUAL environment variable determines which editor is used when the -e option is specified. EDITOR If VISUAL is not set, the EDITOR environment variable determines which editor is used when the -e option is specified. The following environment variables affect the execution of crontab: LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_CTYPE Determines the internationalized environment for the interpretation of bytes of text data as characters (e.g. single-byte characters as opposed to multibyte characters in arguments and input files). LC_MESSAGES Determines the format and contents of error messages. NLSPATH Determines the position of message catalogs for the processing of LC_MESSAGES. Example 1 You want the system to remind you on May 15 every year that it is Aunt Jemima’s birthday. To do this, you set up a file called birthday with the following contents: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 0 0 15 5 * echo Today is Aunt Jemima's birthday !!! Please note that since you only wish to make an entry for the day of the month and not for the day of the week, you must enter an asterisk in the "day of week" field. You now pass the file named birthday to your crontab file: $ crontab birthday The system will then send you the appropriate message via mailx at 00.00 hours on May 15 of each year. This will obviously only function if the system has not been turned off during that night. U22794-J-Z125-6-76 243 crontab Example 2 Let us assume that on every Monday, at 1:30 p.m., you want to remind yourself and a coworker of your aerobics class that evening. Your reminder is to be displayed on the screen. You are at terminal tty007 and she is at terminal tty014. You can also include comment lines in the input text so that your text is easier to read with crontab -l at a later stage. Your crontab file could then be set up as follows: # * = all legal values # n-n = range # n,n = list # Day of week: 0 = Sunday # # Min Hrs Day(Mon) Mon # 30 13 * * 30 13 * * Day(Wk) 1 1 Command echo Aerobics this evening ! >/dev/tty007 echo Aerobics this evening ! >/dev/tty014 Every Monday at 1:30 p.m., you and your colleague will now receive the message "Aerobics this evening !" at your respective terminals (and not in your mailboxes). Example 3 Every Monday, you want to mailx the message below to user melodie, who works on a system called jukebox: It may be blue But it will pass too! You do this by putting the following line in your crontab file: 0 0 * * 1 mailx melodie@jukebox %It may be blue %But it will pass too! See also 244 at, mailx, sh, vi U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc csplit csplit split files based on context csplit splits the contents of a file or the text it reads from standard input into smaller sections and writes all or some of these sections to separate output files. The original file is left unaltered. The way in which csplit divides a file and the sections for which output files are created are specified in the command-line arguments. csplit creates a maximum of 100 output files per call. Syntax csplit[Ë-ks][Ë-fËname][Ë-nËnumberl]ËfileËarg1...argn No option specified The output files are named xx00, xx01, and so on. For each output file that it creates, csplit writes a character count on standard output. Any files that have already been created are removed if an error occurs. option -fËname The output files are called name00, name01, etc. -f not specified: The output files are named xx00, xx01, and so on. -k Files that have already been created are retained if an error occurs. -nËnumber The current number of the output files comprises number digits, whereby 1 Î number Î 9. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example For -nË4, the output files are called xx0000, xx0001 etc. -n not specified: The current number consists of 2 digits. -s The output of a character count is suppressed. file Name of the input file. If you use a dash (-) as the name for file, csplit reads from standard input. arg1...argn You can specify several arguments, each of which references a particular line in the input file. These lines represent the points at which csplit is to split the file into sections. Each dividing line becomes the first line of a new section. If you specify n arguments, csplit divides the file into n+1 sections. U22794-J-Z125-6-76 245 csplit These sections contain the following lines: Section Contents 0 All lines from the start of the input file up to but not including the line referenced by the first argument. 1 All lines from the first dividing line up to but not including the line referenced by the second argument. : : n All lines from the line referenced by the nth argument to the end of the input file. csplit usually writes each section to a separate output file. This does not apply when the argument %regular_expression%[+number][-number] is used (see below). The last section (section n) is always written to an output file. The arguments you specify are processed by csplit in the order in which you list them. To begin with, the first line of the input file is the current line. After an argument has been processed, the line referenced by this argument becomes the current line. The line referenced by the next argument must lie in the range between but not including the current line and the end of the input file. Thus the line referenced by the second argument must come after the line referenced by the first argument. argument can be specified as follows: /regexp/[+number][-number] An argument in the form /regexp/ references the next line after the current line that matches the specified regular expression. The section from the current line up to but not including the line that matches the regular expression is written to an output file. The line matching the regular expression now becomes the current line. The +number or -number offset shifts the dividing line number lines after (+) or before (-) the line that matches the regular expression. The line that is number lines after (+) or before (-) the line matching the regular expression thus becomes the current line. Simple regular expressions (see Tables and directories, Regular POSIX shell expressions) are recognized. If the argument contains blanks or shell metacharacters (see Tables and directories, POSIX shell metanotation), you must either escape every such character with a backslash \ or enclose the whole argument in single quotes ’...’. The regular expression must not contain any newline characters. 246 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc csplit %regexp%[+number][-number] An argument in the form %regexp% references the next line after the current line that matches the specified regular expression. The line that matches the regular expression becomes the current line. csplit in this case does not create an output file for the relevant section. 7. Juli 2009 Stand 11:58.28 If the +number or -number offset is also specified, the current line will be the line that is number lines after (+) or before (-) the line containing the regular expression. Simple regular expressions (see section “Regular POSIX shell expressions” on page 877) are recognized. If the argument contains blanks or shell metacharacters (see section “Metacharacters for the POSIX shell” on page 884), you must either escape every such character with a backslash \ or enclose the whole argument in single quotes ’...’. The regular expression must not contain any newline characters. num This argument references the line with line number num. csplit writes the section from the current line up to but not including the numth line to an output file. The numth line then becomes the current line. {n} This argument is an abbreviation for n arguments of the previous type (see above) and means: "repeat the preceding argument n times", where n is an integer greater than 1. The {n} argument can be entered after any of the above-mentioned arguments, with a blank to separate them. Thus if it follows an argument in the form /regexp/+number][-number] or %regexp%[+number][-number], this argument will be repeated n times. Example Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 ’/regexp/’ {2} is an abbreviation for ’/regexp/’ ’/regexp/’ ’/regexp/’ If {n} follows an argument of the num type, the file will be split n times, from the numth line onward, into sections of num lines each. Example 100 {2} is an abbreviation for 100 200 300 Error argument - out of range The line referenced by the specified argument lies outside the permissible range. The legal range is from, but not including, the current line to the end of the file. 100 file limit reached at arg ... You have specified so many arguments that csplit would need to create more than 100 output files. U22794-J-Z125-6-76 247 csplit Locale The following environment variables affect the execution of csplit: LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_COLLATE Determines the internationalized environment for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. LC_CTYPE Determines the internationalized environment for the interpretation of byte sequences as characters (e.g. single-byte characters as opposed to multibyte characters in arguments and input files) and the behavior of character classes within regular expressions. LC_MESSAGES Determines the format and contents of error messages. NLSPATH Determines the position of message catalogs for the processing of LC_MESSAGES. Example 1 The file book contains a text that is subdivided into three chapters. The first chapter is preceded by a preface; an appendix follows the last chapter. Each chapter begins with the title "CHAPTER ..."; the title of the appendix is "APPENDIX". You now wish to put the preface, the individual chapters, and the appendix into separate files. The output files are to be named chap00, chap01, etc. $ csplit -f chap book '/CHAPTER/' '/CHAPTER/' '/CHAPTER/' '/APPENDIX/' 1636 15124 32743 20344 2576 $ ls book chap00 chap01 chap02 chap03 chap04 248 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc csplit The file chap00 contains the preface and consists of 1636 characters. The appendix is located in the file chap04. The same results could also have been obtained by abbreviating the csplit call as follows: $ csplit -f chap book '/CHAPTER/' {2} '/APPENDIX/' : You can now edit the sections separately, and later you can join them again using cat: $ cat chap0[0-4] > book Example 2 The input file file is to be split into sections every hundred lines. To do this, you enter: $ csplit file 100 {98} The argument {98} stands for 98 arguments: 200 300 ... 9900. If file contains 9900 or more lines, csplit creates 100 output files. The first output file xx00 includes line 1 to 99 (inclusive); the last output file, xx99, contains the rest of file from line 9900 onward. If file contains fewer than 9900 lines, csplit issues the error message "{98} - out of range" and terminates. If you include option -k in the call, the files already created are retained. $ csplit -k file 100 {98} If file contains only 9830 lines, for example, then xx98 is the last output file created and includes lines 9800 to 9830. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example 3 The file prog.c contains a C source program. The program includes a main function and a maximum of 20 further functions. In accordance with C conventions, each function ends with a right brace at the beginning of a line (in column 1). Right braces within a function are not located in the first column of a line. Each function is now to be written to a separate file. To do this, you enter: $ csplit -k prog.c '%main(%' '/^}/+1' {19} If the program contains exactly 20 functions in addition to the main function, csplit splits the file into 22 sections. Section 0 contains all lines from the beginning of the file up to but not including the start of the main function. This section will not be written to an output file (argument %main(%). Section 1 contains the main function and is written to the output file xx00 (argument /^}/+1). Functions 1 to 19 are similarly written to separate output files in succession (argument {19}). The final section, i.e. section 22, contains the rest of the input file (which in this case is function 20) and is written to the output file xx20. If the program contains fewer than 20 functions, csplit will terminate at the last function and issue the error message "{19} - out of range". Since the -k option has been set, the created files will, however, be retained. See also ed, sh, split U22794-J-Z125-6-76 249 cut cut cut out selected fields of each line of a file cut reads the input text line by line from files or from the standard input and cuts out of each line selected bytes (Format 1), characters (Format 2) or fields (Format 3). cut outputs the removed components at the standard output. Syntax Format 1: cutË-bËlistË[-n][Ëfile..] Format 2: cutË-cËlist[Ëfile]... Format 3: cutË-fËlist[Ë-dËchar][Ë-s][Ëfile]... Format 1 Cutting out bytes cutË-bËlistË[-n][Ëfile..] -bËlist (bytes) cut cuts out of each input line the bytes which are in the position specified in list and sends them to the standard output. list is a list of numbers or numerical ranges. The elements in the list must be separated by commas and arranged in ascending order. The range n1-n2 refers to all the numbers between n1 and n2 inclusive. The following abbreviations can be used to specify ranges: -n for 1-n n- for n-"last column" Example 1,3,5 cut cuts the 1st, 3rd and 5th columns. 1-3,5 cut cuts the 1st, 2nd, 3rd and 5th columns. -3,5 is an abbreviation for 1-3,5 3- is an abbreviation for 3-"last column" -n A character which may consist of multiple bytes is not cut out byte by byte. Every list character which is specified in the range n1-n2 is treated as follows: If n1 is not the first byte of the character, then n1 is ignored in order to cut the first byte of the character. If n2 is not the last byte of the character, then n2 is ignored. The last character to precede n2 is selected. n2 is reset to zero if there is no preceding character. file Name of the input file. You may input multiple files. file not specified: cut reads from the standard input. 250 U22794-J-Z125-6-76 Format 2 Cutting out columns cutË-cËlist[Ëfile]... -cËlist (column) The columns specified in list are cut out from each input line and written to standard output. A column is exactly one character wide. list possesses the format described under Format 1. 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cut file Name of the input file. You may name more than one file. file not specified: cut reads from standard input. Format 3 Cutting out fields cutË-fËlist[Ë-dËchar][Ë-s][Ëfile]... -fËlist (field) cut cuts out the fields specified in list from each input line and writes them on standard output. A field comprises all characters that are located between two field delimiters. Two successive field delimiters mark an empty field. The field delimiter defaults to the tab character, but you can redefine it in the -d option. The output fields are separated from one another by one field delimiter each. Input lines with no field delimiters are output in full (unless the -s option is set). This is generally useful for table subheadings. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 list is specified as described under Format 1. -dËchar The character given as char serves as the field delimiter. If char is a blank or a shell metacharacter (see section “Metacharacters for the POSIX shell” on page 884) it must be enclosed in single quotes: -d’char’. -d not specified: The field delimiter defaults to the tab character. -s Lines with no field delimiters are suppressed. -s not specified: Lines with no field delimiters are output in full. file Name of the input file. You may name more than one file. file not specified: cut reads from standard input. U22794-J-Z125-6-76 251 cut Error ERROR: line too long A line can have no more than 1023 characters or fields. Alternatively, the newline character may be missing. cut: Bad list for b/c/f option Incorrect list specification or missing option -b, -c or -f. No error is reported if the line possesses fewer fields than are required by list. cut: No delimiter The delimiter character missing from the -d option. ERROR: cannot handle multiple adjacent backspaces Adjacent backspaces cannot be processed correctly. cut: Cannot open file The named file cannot be read or does not exist. If multiple files have been specified, processing will continue on the other files. Locale The following environment variables affect the execution of cut: LANG Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_CTYPE Determines the internationalized environment for the interpretation of byte sequences as characters (e.g. single-byte characters as opposed to multibyte characters in arguments and input files). LC_MESSAGES Determines the format and contents of error messages. NLSPATH 252 Determines the position of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoc.doc cut Example 1 Print the first 72 characters of each input line: $ cut -c1-72 file Example 2 The first and third fields of the /etc/group file (the group name and group number) are cut out and output. The individual fields in this file are separated by means of a colon. $ cut -f1,3 -d: /etc/group Example 3 The names of customers whose bills are due on the first day of any month are to be filtered out of the invoice file of a mail order house along with the amount due from each of them. The file is structured as follows: Homewood Mackenzie Macnamara Tinniswood Milwaukee Detroit Boston Atlanta 10,000 7,000 8,000 450 06.01.05 07.06.05 05.01.05 06.20.05 The fields in the table are separated by exactly one tab and padded with blanks. $ grep '\.01\.05' invoice $ cat names Homewood 10,000 Macnamara 8,000 | cut -f1,3 > names Explanation: grep finds all lines containing the string .01.05 and writes them to standard output. cut receives these lines as input, selects the first and third fields, and writes its output to the file names. If you would then like each customer name in the names file to be preceded by the date and then sorted accordingly, you could enter: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ grep '\.01\.05' invoice $ paste date names • sort 05.01.05 Macnamara 06.01.05 Homewood | cut -f4 > date 8,000 10,000 Explanation: The first command line writes the date associated with the selected customer names to the file named date. The paste command pastes the lines in the date and names files horizontally, separating them with the default tab character. The sort command then sorts the output lines in ascending order of date. See also awk, grep, paste U22794-J-Z125-6-76 253 date date Built-in sh command write the date and time date writes the current date and time on standard output. The form in which date outputs dates and times depends on the value of the environment variable LC_TIME or, if that is undefined or null, on the value of LANG. If both are undefined or null, or if the required database is not available, or if one of the NLS variables has an invalid value, date acts as if in a non-internationalized system, printing dates and times in American format. Mode of operation The system works with UTC (Universal Time Coordinated; this is the same as GMT Greenwich Mean Time). date converts UTC to local time and vice versa. If the environment variable TZ is defined and option -u is not set then this variable is used to determine the time zone and convert UTC to local time. Syntax Format 1: date[Ë-u][Ë+format] Format 2: dateË-a[Ë-]Ësss.fff Format 1 date[Ë-u][Ë+format] No argument specified date prints the current date and time in a format governed by the current locale. -u Displays the current date and time in Greenwich Mean Time (GMT). If the -u option is set, the +format specification is ignored. +format The format argument defines the output format for date. If format contains blanks or tabs or other shell metacharacters which you do not want the shell to interpret, you should enclose format in single quotes: +’format’. format is essentially similar in format to the first argument of the printf() function in C or awk (see awk, printf (page 140) and the C function printf() [4]). The output of date can be formatted by means of field descriptors in the format argument. Field descriptors take the form of a percentage sign followed by a letter and are replaced in the output by their values (see page 255). All characters that are not part of a field descriptor are copied to the output unmodified. The output is always terminated with a newline character. 254 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc Built-in sh command Format 2 date dateË-a[Ë-]Ësss.fff -a[Ë-]Ësss.fff Adjusts the system clock time by sss.fff seconds, where fff represents fractions of a second. This adjustment can be positive or negative (-). The system's clock will be sped up or slowed down until it has changed by the specified amount. Field descriptors The following overview lists all legal field descriptors. Although the field descriptors %h and %b are essentially identical, both descriptors have been retained for compatibility reasons. %n newline character %t tab character %c date and time in the default format of the current locale %C century (first two digits of the year, 00-99) %D date in the format %m/%d/%y %x date in the format of the current locale %y year (last two digits of the year, 00-99) %Y year (last two digits of the year, 00-99) %m month %h month (in letters, abbreviated) in the format of the current locale %b identical to %h %B month (in letters, in full) in the format of the current locale %W week number of year (00 to 53, with Monday as the first day of the week) %V week number of the year (01 to 53, with Monday as the first day of the week). The first week in January is counted as week 1 if it contains at least 4 days. Otherwise this week is counted as week 53 of the previous year %U week number of the year (00 to 53, with Sunday as the first day of the week) %j day of year (001 to 366) %d day of month (01 to 31) %e day of month (1 to 31, single-digit numbers preceded by a blank) %a abbreviated weekday name in the format of the current locale %A full weekday name in the format of the current locale %w day of week (0 to 6, Sunday = 0) %u day of week (1 to 7, Monday = 1) %R time in the format %H:%M U22794-J-Z125-6-76 255 date Built-in sh command %T time in the format %H:%M:%S %X time in the format of the current locale %r time in a.m./p.m. notation, as %I:%M:%S %p %H hour (00 to 23) %I hour (01 to 12) %p string containing ante-meridiem or post-meridiem indicator(a.m./p.m. affix) in the format of the current locale. %M minute (00 to 59) %S second (00 to 61) %Z timezone name, or no output if no timezone exists (governed by the value of the environment variable TZ, see POSIX shell variables). Modified field descriptors If an alternative representation is defined in your local environment(e.g. before and after Christ) you can call it using modified field descriptors. Modified field descriptors are in the form %Eletter or %Oletter. The modified field descriptors that can be used are listed in the overview below. If no alternative representation has been defined, all modified field descriptors output the value of the current unmodified field descriptors. %Ec date and time in the alternative format %EC name of the time period (e.g. "year") in the alternative representation %Ex date in the alternative format %EX time in the alternative format %Ey year in which the time period in the alternative representation begins %EY year in the alternative representation %Od day of month in alternative numeric representation %Oe day of month in alternative numeric representation %OH hour (24-hour clock) in alternative numeric representation %OI hour (12-hour clock) in alternative numeric representation %Om month in alternative numeric representation %OM minutes in alternative numeric representation %OS seconds in alternative numeric representation %Ou weekday in the alternative format (Monday = 1) %OU week of the year in alternative numeric representation (same as for %U) 256 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc Built-in sh command date %OV week of the year in alternative numeric representation (same as for %V) %Ow weekday in the alternative format (Sunday = 0) %OW week of the year in alternative numeric representation (same as for %W) %Oy year in the alternative format Variable TZ If defined, the environment variable TZ contains information on timezones. date uses TZ to determine the timezone and to convert from UTC (Universal Time Coordinated) to local time and vice versa. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The default value "MEZ-1MSZ-2,M3.5.0/02:00:00,M10.5.0/03:00:00" of the TZ variable must be interpreted as following: – Standard time zone Name MEZ Time difference Zone - 01:00:00 = UTC – Alternative time zone Name MSZ Time difference Zone - 02:00:00 = UTC – Switchover time to the alternative time zone Month 3 = March Week 5 (or 4) Weekday 0 = Sunday Time 02:00:00 – Switchover time to the standard time zone Month 10 = October Week 5 (or 4) Weekday 0 = Sunday Time 03:00:00 Locale The following environment variables affect the execution of date: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). U22794-J-Z125-6-76 257 date Built-in sh command LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. 258 LC_TIME Determine the format and contents of date and time strings written by date. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 Example date Printing date and time If you call date without arguments at 17:00 hours EST on June 19, 2009, and the system clock is set to the correct time, the following will be printed Fri Jun 19 17:00:00 MSZ 2009 The command: $ date '+DATE: %m/%d/%y%nTIME: %H:%M:%S' 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc Built-in sh command generates the following output: DATE: 06/19/09 TIME: 17:00:00 You have defined the environment variable CFTIME and used echo to output the value of CFTIME: $ echo $CFTIME %d %B %y If the system clock is set correctly then, on 19 June 2005 at 17.00 CET, a call to date with no argument results in the output 19 June 05 cal ctime(), printf() [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 259 dd dd convert and copy a file The dd command can be used to copy files while making any necessary conversions, e.g. from EBCDIC to ASCII or vice versa. dd is well-suited for input/output via raw devices (raw physical I/O), because it can read and write in blocks of any size. Note, however, that any given raw device can only handle the block sizes for which it is specifically designed (512-byte blocks for a floppy disk drive, for example. If the size of the file you want to convert is not a multiple of the appropriate block size, you must use the conv=sync option. After completion, dd reports the number of whole and partial input and output blocks on standard error. Caution! Never use dd to copy files between file systems which have different block sizes. Using a block device to copy a file may result in extra nulls being added to the file to pad the final block to the block boundary. ! Syntax dd[Ëoption...] No option specified dd reads from standard input and writes to standard output. No conversions are performed. The input and output block sizes default to 512 bytes. option 260 Option Brief description if=input_file Name of input file of=output_file Name of output file ibs=n Input block size (in bytes) obs=n Output block size (in bytes) bs=n Input and output block size (in bytes) cbs=n Conversion buffer size (in bytes) skip=n Skip first n blocks of input file iseek=n Seek n blocks from beginning of input file before copying oseek=n Seek n blocks from beginning of output file before copying seek=n Seek n blocks from beginning of output file before copying count=n Copy/convert only first n blocks of input file conv=value[,value...] Several values for conv conv=ascii Convert from EBCDIC to ASCII U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc dd Option Brief description conv=ebcdic Convert from ASCII to EBCDIC conv=siemens Convert from ASCII to Siemens-specific EBCDIC conv=ibm Convert from ASCII to IBM-specific EBCDIC conv=block Convert newline-terminated records to fixed-length records conv=unblock Convert fixed-length records to newline-terminated records conv=lcase Convert uppercase letters to lowercase conv=ucase Convert lowercase letters to uppercase conv=swab Swap every pair of bytes conv=noerror Do not stop processing on error conv=sync Pad every input block to the number of characters defined in ibs=n conv=notrunc Do not truncate the output file Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If size arguments are needed for an option, you can specify them as follows: n means n times 1 nb means n times 512 nk means n times 1024 nw means n times 2 nxm means n times m if=input_file In input_file you give the name of the input file from which dd is to read. if=input_file not specified: dd reads from standard input. of=output_file output_file designates the name of the output file to which dd is to write. of=output_file not specified: dd writes to standard output. ibs=n (input block size) In n you specify the input block size in bytes. ibs=n not specified: The input block size defaults to 512 bytes. U22794-J-Z125-6-76 261 dd obs=n (output block size) In n you specify the output block size in bytes. obs=n not specified: The output block size defaults to 512 bytes. bs=n (block size) In n you specify a value in bytes for both the input and output block size. The value specified for bs overrides the values of ibs and obs. cbs=n (conversion buffer size) In n you specify a value in bytes for the conversion buffer size. This specification is only effective in the following cases: – for conversions from EBCDIC to ASCII and vice versa – for conversions from and to fixed-length records. (see conv=ascii, conv=ebcdic, conv=ibm and conv=block, conv=unblock, page 263). skip=n The first n blocks of the input file are skipped, and copying begins at block number n+1. This option is only appropriate for magnetic tape, where iseek is undefined. iseek=n The first n blocks of the input file are skipped, and copying begins at block number n+1. This option is specially designed for disk files, where skip can be extremely slow. It is only accepted with devices which support the lseek system call (such as disk units). skip and iseek are mutually exclusive. oseek=n The copy of the input file (after conversion, if specified) begins n blocks into the output file (i.e. at block n+1). The first n blocks of the output file remain unchanged. This option is only accepted with devices which support the lseek system call (such as disk units). seek=n seek performs the same function as oseek. count=n Only the first n blocks of the input file are copied (and converted, if specified). conv=value[,value...] You can specify several comma-separated values for conv and thus have a number of conversions performed. The values ascii, ebcdic and ibm cannot be used in combination. The same applies to the pairs block and unblock, and lcase and ucase. 262 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc dd conv=ascii Conversion from EBCDIC to ASCII. The number of characters defined in cbs=n is copied into the conversion buffer and any specified character mapping is done. Trailing blanks are removed, and a newline character is added. The output block size of the file is thus adjusted to the value defined in cbs=n. If cbs is unspecified or set to 0, input file character mapping is done, but trailing blanks are not removed. conv=ebcdic Conversion from ASCII to EBCDIC. The ASCII characters are read into the conversion buffer and converted to EBCDIC. Trailing blanks are added in order to produce the output block size defined in cbs=n. If cbs is unspecified or set to 0, input file character mapping is done, but the file’s block structure is not changed. conv=siemens Conversion from ASCII to EBCDIC as described above, but by using a Siemens-specific EBCDIC table. The Newline character is converted as follows:: X'0A' <-> X'05' . conv=ibm Conversion from ASCII to EBCDIC as described above, but using an IBM-specific EBCDIC table. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 conv=block Conversion of newline-terminated ASCII records to fixed-length records. The ASCII characters are read into the conversion buffer, and blanks are added to adjust the record length or output block size to the value defined in cbs=n. If cbs is unspecified or set to 0, this option produces a simple file copy. conv=unblock Conversion of fixed-length ASCII records to newline-terminated records. The record length is determined by the value defined in cbs=n. This number of characters is repeatedly read into the conversion buffer, where excess trailing blanks are removed and a newline character is added before the characters are sent to the output. If cbs is unspecified or set to 0, this option produces a simple file copy. conv=lcase Uppercase letters are converted to the corresponding lowercase letters. conv=ucase Lowercase letters are converted to the corresponding uppercase letters. conv=swab The bytes in each pair of bytes are swapped. If an input block contains an uneven number of bytes, the last byte is ignored. U22794-J-Z125-6-76 263 dd conv=noerror Processing is continued even if an error occurs. conv=sync Every input block is padded to the value specified in ibs=n. When block or unblock is specified, blanks are used, otherwise null-bytes. conv=notrunc The output file is not regenerated. All blocks that are not overwritten explicitly by dd remain unchanged. Locale The following environment variables affect the execution of dd: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. The contents of an EBCDIC tape with a block structure of 10 times 80 bytes is to be written to the ASCII file xy: $ dd if=/dev/rmt32 of=xy ibs=800 cbs=80 conv=ascii See also 264 cp U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc debug debug program debugging in forked tasks The debug command enables POSIX programs which can be started from within a shell to be debugged. Syntax Format 1: debug[Ë-e]Ëprogram[Ëarguments]... Format 2: debug[Ë-p]Ëpid Format 1 debug[Ë-e]Ëprogram[Ëarguments]... The program to be debugged is loaded in the task generated from within the shell by means of a fork (fork task). Once the program has been loaded, but before the first command is executed, control is passed to the user on BS2000 command level. The process ID of the fork task is displayed as a prompt (see also Example 1 below). -e program is loaded without its external symbols dictionary. program Name of the program to be debugged. The program must be executable. arguments program arguments. Format 2 debug[Ë-p]Ëpid The program running in the fork task with process ID pid is stopped. The user is given control on BS2000 command level. The process ID of the interrupted fork task is displayed as a prompt (see also Example 2 on page 266). -p Interrupts the program in the task with process ID pid. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 pid Process ID of the task that is to be stopped. Example 1 The example below illustrates what happens up to the point where the program to be debugged is loaded. When the prompt pid/ appears, the program is ready to start as it would be after a /LOAD-PROGRAM command. AID commands can be used to influence how debugging is to proceed. The program starts again after the /RESUME-PROGRAM command in the fork task. /START-POSIX-SHELL $ cd myprogdir $ ls -l myprog -rwxr-xr-x 1 MYUSER MYGROUP 1150976 Wed May 11 13:10:50 MSZ 2005 myprog $ debug myprog % AID0348 Program stopped due to EXEC event (PID=0000000055) 0000000055/ U22794-J-Z125-6-76 265 debug Example 2 This example illustrates what happens when a program executing in a fork task is interrupted. When the pid/ prompt appears, the program has been interrupted as when [K2] is pressed. AID commands can be used to influence how debugging is to proceed. The program starts again after the RESUME-PROGRAM command in the interrupted fork task. /START-POSIX-SHELL $ ps -e UID PID PPID SYSROOT 243 1 SYSROOT 245 243 C 0 0 STIME TTY 16:32:38 term/001 16:33:44 term/001 TIME 0:01 0:00 CMD [sh] [loop] $ debug -p 245 % AID0492 %STOP was send for fork task (PID=0000000245) $ % AID0348 Program stopped due to STOP event (PID=0000000245) 0000000245/ 266 U22794-J-Z125-6-76 df report free disk space You can use df to determine the number of free disk blocks and inodes which are still available at mounted or unmounted local systems and to obtain information on the file system coding (ASCII or EBCDIC). Syntax 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc df Format 1: df[Ë-FËFSType]Ë -P[Ë-klV][Ëfile] Format 2: df[Ë-FËFSType][Ë-begklntVv][Ë-oËufs_options]...[Ëfile] Format 3: dfË-c[Ëfile]... Format 1 df[Ë-FËFSType]Ë -P[Ë-klV][Ëfile]... option -FËFSType The file system with which you want to work is of the type FSType. You only need to specify this option if the file system is unmounted. FSType may be: ufs Berkeley file system bs2fs bs2fs file system proc Pseudo file system for accessing process data fdfs Pseudo file system for accessing file descriptors filesystem Special file for the file system © cognitas GmbH 2001-2007 bytes Total disk space in 512-byte blocks used Used disk space in 512-byte blocks available Available disk space in 512-byte blocks Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 -P Prints the following information in columns for all mounted file systems or for the specified file systems: capacity Percentage of disk space used mounted on Name of the directory on which the file system is mounted -k Prints the following information in columns for all mounted file systems or for the specified file systems (like option -P). Storage space is listed in 1024-byte blocks (instead of 512-byte blocks). The storage space specification takes account of the reserved storage space which can only be used by the POSIX administrator. U22794-J-Z125-6-76 267 df -l df prints the number of free blocks and inodes for all locally mounted file systems or for the specified file systems. The -l option is set by default. It cannot be combined with -e or -o. -V df expands the df command line and writes the completed command to standard output, but does not execute the command. df completes the command line, adding information derived from /etc/mnttab and /etc/vfstab to input provided by the user. The added information relates to the option -FËFSType and/or the associated special file, depending on which of the two components, if either, was specified on the command line. If you enter dfË-V without other options and arguments, you will be shown a list of df command lines indicating all mounted file system types and the associated special file names. file file is either the name of a directory or the name of a special file which contains a file system. If you name a directory, df examines the file system mounted on that directory. You may name more than one file. file not specified: df prints out information on all mounted file systems or all file systems of type FSType. Format 2 df[Ë-FËFSType][Ë-begklntVv][Ë-oËufs_options]...[Ëfile]... No option specified df prints the number of free blocks and inodes in all mounted or all specified file systems. option -FËFSType The file system with which you want to work is of the type FSType. You only need to specify this option if the file system is unmounted. FSType may be: ufs Berkeley file system bs2fs bs2fs file system proc Pseudo file system for accessing process data fdfs Pseudo file system for accessing file descriptors nfs File system mounted on the remote host (network file system, Berkeley) -b Prints the free disk space (in Kbytes). This option cannot be combined with -o. -e Prints the number of free inodes. This option cannot be combined with -o, and it overrides the -l option. 268 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc df -g Prints the entire statvfs structure for all mounted file systems or for FSType or file. The output consists of 4 lines containing the following information: dir Name of the directory on which the file system is mounted (the string dir does not appear in the output) device Associated special file (the string device does not appear in the output) block size Block size of the file system frag size Fragment size of the file system total blocks Total number of blocks in frag size units free blocks Total number of free blocks available Number of free blocks for non-POSIX administrators total files Total number of inodes free files Number of free inodes filesys id File system identification number name File system designation (the string name does not appear in the output) fstype File system type flag File system flags filename length Maximum length of file names Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 This option cannot be combined with -o, and it overrides options -b, -e, -k, -l, -n, -r and -v. -k Prints the following information in columns for all mounted file systems or for the specified file systems: filesystem Special file associated with the file system kbytes Total disk space in 1024-byte blocks used Used disk space in 1024-byte blocks avail Available disk space in 1024-byte blocks capacity Percentage of disk space used mounted on Name of the directory on which the file system is mounted The storage space specification takes account of the reserved storage space which can only be used by the POSIX administrator. This option cannot be combined with -o, and it overrides options -b, -e, -k, -l, -n, -r and -v. U22794-J-Z125-6-76 269 df -l df prints the number of free blocks and inodes for all locally mounted file systems or for the specified file systems. The -l option is set by default. It cannot be combined with -e or -o. -n df outputs the file system type. If you combine -n with -o or -f then an error message is displayed. -t df prints the number of free blocks and files as well as the total number of available blocks and files for each mounted or specified file system. -t overrides the -b option. Combining -t with -o i produces a totals line for all the columns in the -o i output. -V df expands the df command line and writes the completed command to standard output, but does not execute the command. df completes the command line, adding information derived from /etc/mnttab and /etc/vfstab to input provided by the user. The added information relates to the option -FËFSType and/or the associated special file, depending on which of the two components, if either, was specified on the command line. If you enter dfË-V without other options and arguments, you will be shown a list of df command lines indicating all mounted file system types and the associated special file names. -v df prints the following information in columns for all mounted file systems or for the specified file systems: Mount Dir Name of the directory on which the file system is mounted Filesystem Special file associated with the file system blocks Total disk space, in 512-byte blocks used Used disk space, in 512-byte blocks free Free disk space, in 512-byte blocks %used Percentage of disk space used This option cannot be combined with -o, and it overrides options -b, -e, -k, -l, -n, -r and -v. 270 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc df -oËufs_option If the file system type is ufs, you can use a ufs-specific option: 7. Juli 2009 Stand 11:58.28 i df prints the following information in columns: Filesystem Name of the special file Filesystem Name of the associated special file iused Number of used inodes ifree Number of free inodes %iused Percentage of inodes used Mounted on Name of the directory on which the file system is mounted The only options with which -oËi can be combined meaningfully are -F and -t. file file is either the name of a directory or the name of a special file associated with a file system. If you name a directory, df examines the file system mounted on that directory. You may name more than one file. file not specified: df examines all locally and remotely mounted file systems or all file systems of type FSType. Format 3 dfË-c[Ëfile]... option Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -c The command outputs the type of coding (ASCII or EBCDIC) for all locally mounted file systems or those specified with file. This option cannot be combined with other options. Hint In UFS file systems the available disk space is as a rule less than the free disk space. The reason for this is that some of the disk space (10%) is reserved for privileged applications and is consequently not available for normal applications. Error Some of the following error messages also indicate the correct syntax, but use some syntax elements that differ from the ones in the above description. The table below shows which syntax elements are equivalent: Syntax element in the error message Equivalent in the above description specific_options ufs_option directory | special file generic options -begkltvV U22794-J-Z125-6-76 271 df df: Cannot access file An invalid or incomplete special file or directory name was specified with dfË-V . df ufs: Usage: df [-F ufs] [generic options] [-o i] [directory|special] An invalid ufs_option argument was specified with the -o option. ufs_option can only be i. df: operation not applicable for FSType FStype An invalid file system type (xxx) was specified for FSType in the command dfË-FËFSTypeË-oËi. The only type that can be specified in combination with the -o option is ufs. File /dev/dsk/* Special files associated with the file systems /etc/mnttab Table of mounted file systems /etc/vfstab List of default parameters for each file system /etc/fs/FStyp/* Commands for specific file system types Locale The following environment variables affect the execution of df: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH 272 Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc df Example 1 Printing the associated file system types for all user directories: $ df -n /h* /home : ufs /home2 : ufs /home3 : ufs Example 2 Printing the entire statvfs structure for the file system /stand: $ df -g /stand 10710 100 bfs /stand (/dev/dsk/c0d0s10): total blocks 7577 free blocks free files 10 filsys id fstype 0x00000000 flag 512 block size 7577 available 512 frag size 104 total file /stand 14 filename length Example 3 The file system coding is to be output for the /home and /var directories: $ df -c /home /var /home : EBCDIC /var : ASCII du Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 273 diff diff compare two files The diff utility will compare the contents of file1 and file2 and write to standard output a list of changes (with ed-like commands) necessary to convert file1 into file2. This list should be minimal. No output will be produced if the files are identical. Syntax diff[Ëoption]Ëfile1Ëfile2 No option specified If the compared files are identical, diff produces no output. When the files differ, the output is as follows: 1. line[range] from ed command file1 2. lines that are only in file1 3. lines that are only in file2 line[range] from file2 The lines are displayed in the following format: 1. n1[,n2] a d n1[,n2] c 2. < text of line from file1 . . . - - 3. > text of line from file2 . . . a, d, and c are ed-like commands meaning: a append d delete c change The output is to be interpreted as follows: The ed commands a, d, and c with their preceding line (or range) specifications show how file1 can be converted into file2. If you replace a with d and d with a and use the line (or range) specifications to the right, the commands indicate how file2 can be converted into file1. Lines from file1 are marked <; those from file2 are marked >. 274 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc diff option -a diff produces a diff with all lines of context from both files. Those lines only in file1 are prepended with -; those only in file2 are prepended with +. Lines which are identical in both files are prepended with Ë.. -b diff ignores trailing blanks or tabs at the end of lines as well as differing numbers of blanks at corresponding positions within text lines. Leading blanks and blank lines are reported as differences. -i -i must not be combined with -h. diff ignores the case of letters; for example, it considers ’A’ to be the same as ’a’. -t diff expands tab characters in output lines. In normal or -c output, diff adds character(s) to the start of each line that may adversely affect the indentation of the original source lines and make the output lines difficult to interpret. The -t option preserves the original source’s indentation. -w diff ignores all blanks (space and tab characters) and treats strings of blanks of any length as equivalent; for example, it considers ’ifË(ËaË=Ë=ËbË)’ to be the same as ’if(a==b)’. The following options are mutually exclusive: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -c diff produces a listing in three parts with a slightly modified output format. The output begins with the names and creation dates of file1 and file2. Then come the lines that differ, with the lines not present in file2 marked with a minus sign (-) and the lines that differ in file1 and file2 marked with an exclamation point (!). There are also three lines of context before and after the differing lines. -CËnumber Produces a listing of differences identical to that produced by -c, but with number lines of context before and after each difference. -e The -e option must not be combined with -h, -l or -s. diff produces output suitable for use as an ed script. The ed script contains a, d, and c commands and the related text lines as input for the editor ed to convert file1 to file2. Before you pass the script to the editor, you should add the statements w and q at the end of the script and insert the command e file1 at the start (see section “ed interactive line editor” on page 289). -f The -f option must not be combined with option -h. diff generates a similar script to the one created with option -e, but converting in the opposite direction. This script, however, is not usable with ed. Editing scripts produced under the -e and -f options may be incorrect when dealing with lines comprising nothing but a single period. U22794-J-Z125-6-76 275 diff The following options modify the way in which diff works: -h The -h option must not be combined with -e, -f, -i, -c, -C, -n or -D. diff operates faster, and you can process files of any length. However, the result produced by option -h is not reliable! -n Produces a script similar to -e, but with the ed commands listed in reverse order. In addition, a count of the lines to be changed is printed after each insert or delete command. -DËstring In this case file1 and file2 must be C source programs or contain C source fragments. diff creates a merged version of file1 and file2 with C preprocessor controls included so that compilation of the result is equivalent to compiling file1 if string is not defined, and is equivalent to compiling file2 if string is defined. The following options are used to compare directories: -l diff produces output in long format. Before checking for differences, diff pipes each text file through pr to paginate it. Differences other than those in text files are remembered and are summarized after all text file differences have been reported. -r Applies diff recursively to all common subdirectories encountered. -s Reports files that are identical; these would not otherwise be mentioned. -SËname Starts a directory diff in the middle, beginning with the file name. file1Ëfile2 Names of the files diff is to compare. If file1 is a directory, then a file in that directory with the same name as file2 is compared against file2. If file2 is a directory, then the comparison is made with a file named file1 from that directory. If both file1 and file2 are directories, diff looks in both directories for files with the same name to compare. In this case diff will not compare block special files, character special files or FIFO special files to any files as well as regular files to directories. If either the file1 or file2 operand is a -, the standard input will be used in its place. In this case the input files must be text files. Exit status 276 0 Files are the same 1 Files are different >1 Input error U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc diff Error diff: two filename arguments required You have specified an incorrect number of files. Only two files can be compared at a time. diff: No such file or directory One of the specified files does not exist. diff: files too big, try -h You need to use the -h option, as the files to be compared are too large. diff: Permission denied You do not have read permission for one of the specified files. Variable TZ Determine the locale for affecting the timezone used for calculationg file timestamps written with the -C and -c options Locale The following environment variables affect the execution of diff: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. LC_TIME Determine the locale for affecting the format of timestamps written with the -C and -c options. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 277 diff Example 1 The files file1 and file2 have the following contents: file1 file2 Jack Jill went up the hill to fetch a pail of water Jack and Jill went uphill of water By calling diff, you can identify the lines in which the two files differ. $ diff file1 file2 1,3c1,2 Jack and Jill >went uphill Explanation: In order to convert file1 into file2, lines 1 to 3 inclusive from file1 (1,3) must be replaced (c) by lines 1 to 2 inclusive (1,2) of file2. The contents of each of these lines are shown in the output lines beginning with the < or > characters. Lines in file1 are marked <; lines in file2 are marked >. Example 2 Compare files and produce an ed script: Contents of file1: Contents of file2: today is monday it is cold today is tuesday it is autumn it is cold After the following command, diff outputs the ed commands with which ed could convert file1 into file2. To be able to use this output as input for ed, you need to add the statements w and q to the end of the ed script. $ diff -e file1 file2 1c today is tuesday it is autumn . $ See also 278 cmp, comm, ed, pr U22794-J-Z125-6-76 dirname return directory portion of pathname dirname can be used to strip the file name (basename) from the full access path. dirname takes a string as its argument, removes the final slash and all characters to the right of it, and writes the rest of the string on standard output. dirname is useful in shell scripts. Syntax 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc dirname dirname[Ëstring] string string can be any string of characters. dirname deletes the final slash and all characters to the right of it and writes the remaining portion to standard output. If string does not contain a slash, a dot is written to standard output. string not specified: a dot is written to standard output. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of dirname: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. In the following example, the path prefix /usr/src/cmd is assigned as a value to the NAME variable: NAME=`dirname /usr/src/cmd/xyz.c` See also basename, U22794-J-Z125-6-76 279 du du estimate file space usage du outputs the amount of disk space used by directories, subdirectories, and ordinary files in blocks of 512 bytes. Syntax du[Ëa |Ës][Ë-kx][Ë-r]...[Ëfile...] No option specified If name is a directory, du lists the space occupied by the specified directory and all its subdirectories. The disk space occupied by ordinary files in the specified directory is included in the count, but not listed individually. If name is not a directory, du does not output anything for it. option -a If file is a directory then du reads the storage space allocated to each of the files in this directory individually. If file is not a directory then du reads the storage space allocated to file. The option -a can be combined with the option -s. -k du outputs the occupied storage space, specifying the number of occupied 1024-byte blocks. -r du issues an error message if file is a directory for which you possess no read permission or if it is a file which cannot be opened. The option -r is always set. -s du only outputs the total amount of storage space occupied by the section of the file tree or the file. The option -s cannot be combined with the option -a. -x When file sizes are calculated, only those files which use the same special file as file are considered. file Name of the file or directory for which disk usage is to be displayed. A file with two or more links is only counted once. A file that has a hole in it (e.g. if only block 1 and block 100 are used) will result in an incorrect block count. If name refers to an ordinary file, du remains silent if invoked without options. file not specified: The disk space occupied by the current directory and all its subdirectories is displayed. Locale The following environment variables affect the execution of du: LANG 280 Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc du LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). 7. Juli 2009 Stand 11:58.28 LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 List the disk usage, in 512-byte blocks, of all subdirectories of the current directory whose names begin with DIR. The space occupied by ordinary files is included, but not listed individually. $ du DIR* 6 DIR-1 136 DIR-2/SUB-1 140 DIR-2 5 DIR-3 54 DIR-4 Example 2 List the disk usage, in 512-byte blocks, of all subdirectories of the current directory whose names begin with DIR. The disk usage of ordinary files is listed individually in this case because the -a option is used. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ du -a DIR* 1 DIR-1/file1 1 DIR-1/file2 1 DIR-1/file3 6 DIR-1 0 DIR-2/file4 1 DIR-2/file5 34 DIR-2/SUB-1/file6 99 DIR-2/SUB-1/file7 136 DIR-2/SUB-1 140 DIR-2 1 DIR-3/file8 1 DIR-3/file9 5 DIR-3 50 DIR-4/file10 1 DIR-4/file10.bak 54 DIR-4 See also df U22794-J-Z125-6-76 281 dumpfs dumpfs dump file system The command dumpfs outputs the super block and cylinder group information for the specified file system. This command can, for example, be used to determine the block and fragment sizes which are specifed for the file system as well as the minimum required storage space in percent. Syntax dumpfsËfile_system file_system Name of the file system for which the information is to be output. i This command may only be entered by the POSIX administrator. It is only of use to system maintenance staff for diagnostic purposes. Hint The dumpfs command is not supported for bs2fs file systems. Example Printing out information on the / directory: # dumpfs / magic 11954 time Thu Jun sblkno 4 cblkno 6 sbsize 4096 cgsize 4096 ncg 2 size 2048 bsize 8192 shift 13 fsize 4096 shift 12 frag 2 shift 1 minfree 10% maxbpg 1024 maxcontig 1 rotdelay 0ms csaddr 72 cssize 4096 ntrak 8 nsect 16 cpg 16 bpg 512 nindir 2048 inopb 64 nbfree 400 ndir 87 cgrotor 0 fmod 0 8 10:04:06 1995 iblkno 8 dblkno cgoffset 8 cgmask blocks 1907 mask 0xffffe000 mask 0xfffff000 fsbtodb 1 rps shift spc fpg nspf nifree ronly 60 9 128 1024 2 2157 0 72 0xfffffff8 mask ncyl ipg 0xfffffe00 32 2048 nffree 5 cs[].cs_(nbfree,ndir,nifree,nffree): (66,29,918,3) (334,58,1239,2) cg 0: magic 90255 tell 6000 time Thu Jun 8 08:35:05 1995 cgx 0 ncyl 16 niblk 2048 ndblk 1024 nbfree 66 ndir 29 nifree 918 nffree 3 rotor 870 irotor 833 frotor 864 frsum 3 sum of frsum: 3 iused: 0-6, 8-832, 835-846, 848-1126, 1129-1134, 1136 282 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.28 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdod.doc dumpfs free: 575, 844-845, 864, 871, 876-881, 894-901, 904-913, 916-917, 920-1023 b: c0: c1: c2: c3: c4: c5: c6: c7: c8: c9: c10: c11: c12: c13: c14: c15: (0) (0) (0) (0) (0) (0) (0) (0) (0) (0) (0) (0) (0) (5) (29) (32) 0 0 0 0 0 0 0 0 0 0 0 0 0 1 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 6 8 cg 1: magic 90255 tell 40e000 cgx 1 ncyl 0 nbfree 334 ndir 58 rotor 234 irotor 716 frsum 2 sum of frsum: 2 iused: 0-805, 807, 809, 811 free: 353, 355-1023 b: c0: (0) 0 0 0 0 0 0 0 c1: (0) 0 0 0 0 0 0 0 c2: (0) 0 0 0 0 0 0 0 c3: (0) 0 0 0 0 0 0 0 c4: (0) 0 0 0 0 0 0 0 c5: (14) 3 0 3 0 4 0 4 c6: (32) 8 0 8 0 8 0 8 c7: (32) 8 0 8 0 8 0 8 c8: (32) 8 0 8 0 8 0 8 c9: (32) 8 0 8 0 8 0 8 c10: (32) 8 0 8 0 8 0 8 c11: (32) 8 0 8 0 8 0 8 c12: (32) 8 0 8 0 8 0 8 c13: (32) 8 0 8 0 8 0 8 c14: (32) 8 0 8 0 8 0 8 c15: (32) 8 0 8 0 8 0 8 U22794-J-Z125-6-76 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 time niblk nifree frotor Thu Jun 8 10:04:51 1995 2048 ndblk 1024 1239 nffree 2 256 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 283 echo echo write arguments to standard output The POSIX shell built-in echo writes its arguments to standard output and terminates. The following takes place before the output is generated: 1. As with every other command, the shell interprets the command line arguments and then passes the edited arguments to echo. The argument separators recognized by the shell are blanks and tabs. 2. echo interprets any remaining special characters that control output (see description of argument below). 3. echo displays processed arguments as follows: – Each argument is separated from the next by a blank even if you have entered more than one argument separator between individual arguments in the call. – A newline character is output at the end of the last argument. You can use echo to – examine values of shell variables, – generate messages in shell scripts and thus test how they function, – test how the shell interprets a command call without the command being executed, – redirect data to a pipe and test how the pipe processes this input. Besides the shell built-in echo, there is also a command called /usr/bin/echo. The shell generates a new process to execute /usr/bin/echo. Otherwise, /usr/bin/echo operates in the same way as echo. Syntax echo[Ëargument...] argument Any string delimited by blanks or tabs. The last argument is terminated by means of a command separator. You may specify any number of arguments, provided they are separated by at least one tab or blank character. As with any other command, this string is also initially interpreted by the shell: 284 – If the string contains an asterisk, question mark, or [...], the shell replaces this string by all suitable file names in the current directory. If no suitable file name is found, the shell passes the string on to echo unaltered. – ’string’ All shell metacharacters are escaped by the single quotes. The shell passes the string as an argument to echo without the quotes. All blanks, tabs and newline characters entered within single quotes are retained. U22794-J-Z125-6-76 – ` string` The shell executes string as a POSIX command and passes the output of this command to echo. Characters assigned to the environment variable IFS are interpreted by the shell in the output as argument delimiters. The default characters assigned to IFS are the blank, tab or newline characters. – "string" The double quotes escape all shell metacharacters except for the backslash \, backquotes ` ...` and the dollar sign $. The shell passes the processed string to echo as an argument. All blanks, tabs, and newline characters within the double quotes are retained. 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc echo The shell built-in echo also interprets the control characters described below. Since the backslash has a special meaning for the shell, it must be escaped: – by preceding it with another backslash \ This also applies if the argument containing this control character is enclosed within double quotes. – by single quotes ’...’ If the argument containing this control character is enclosed within single quotes, the backslash need not be escaped again. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example $ echo hello $ echo hello $ echo hello $ echo hello hello\\tuser user hello’\’tuser user ’hello\tuser’ user "hello\tuser" user Control characters The following control characters influence the output of echo, provided the backslash has been appropriately escaped: Please note the terminal-specific characteristics. \c echo prints the arguments entered up to this control character, omitting the newline and ignoring the remaining arguments. U22794-J-Z125-6-76 285 echo \f (form feed) This control character is not converted if the output is written to the terminal. If the output from echo is sent to a printer, for example, all arguments entered after this control character will be written on the next page. \f corresponds to [CTRL][L] \n (newline) All arguments that follow the newline character are written in the next line. \n corresponds toÚ or [CTRL][J] \t Control character for tab; echo moves the cursor to the next tab stop. Characters entered after \t are written by echo from this column onward. The setting of tab stops depends on the data terminal that is used. On a Siemens Nixdorf 97801 terminal, tab stops are set at the following columns: 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 79 \ t corresponds to ¯ or [CTRL][I] \0n n must be a one, two or three figure octal number. The echo command outputs the corresponding character (see Tables and directories, EDF04 character set). In this way you can, for example, generate characters with an internal code greater than FF (EDF04) even if you do not possess an 8-bit terminal. A dummy character is output to represent non-displayable characters (devicedependent). If a character in octal notation is to be followed by an additional digit that is not part of the octal number, you must use the full three-digit form of the octal number. i Example $ echo ’\0337’|od -xc 0000000 df15 337 \n 0000002 $ echo ’\00337’|od -xc 0000000 1bf7 1500 033 7 \n 0000003 286 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc echo If control characters of the above type are to be interpreted by neither the shell nor echo, they must be entered as follows: Example 7. Juli 2009 Stand 11:58.29 $ echo \ $ echo \t $ echo \t $ echo \t \\ \\\\t ’\\t’ "\\\t" The above example applies to the remaining strings as well. argument not specified: echo produces only a blank line. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of echo: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH U22794-J-Z125-6-76 Determine the location of message catalogs for the processing of LC_MESSAGES. 287 echo Example 1 The following interactive session will demonstrate when blanks, tabs and newline characters are retained: $ echo Today is Today is Monday. Monday. In this case echo receives three arguments and returns them with one blank between each. $ echo "Today is Monday." Today is Monday. All blanks entered within the double quotes are retained. Example 2 User anna wants to know what value is assigned to the HOME variable: $ echo $HOME /home/anna Example 3 The following line in a shell script will cause an error message to be written on standard error: echo File $1 not found >&2 Example 4 A string constant is to be placed before the output of the date command: $ echo "Today's date and time: \\c"; date Today's date and time: Mon Mar 9 17:22:05 MEZ 2009 The control character \c prevents echo from interpreting the newline. The backslash must be escaped despite the double quotes. See also 288 print U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed ed interactive line editor ed is an interactive line editor. Furthermore, with the help of ed scripts (see “Working with ed scripts” on page 303), you can easily process several files with the same sequence of commands. ed can handle the output of the diff -e command (see page 274f). Syntax ed[Ë-|Ë-s][Ë-pËstring][Ëfile] Ë-|Ë-s The -s option corresponds to the old - option, which is still supported. The -s option suppresses the following default outputs: – number of bytes processed by the ed commands: e (edit) r (read) w (write) – the question mark character, which warns against inadvertent deletion of the buffer contents during execution of the ed commands: e (edit) q (quit) – the exclamation mark ! used as an ed prompt after a ! command. -pËstring In string you can define the prompt that ed displays in command mode. string can be one or more characters. -pËstring not specified: ed does not display a prompt string. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file The name of the file that you wish to process. ed copies the file into its internal buffer and saves file as the current file name. file not specified: You start by working on an empty buffer and only decide upon a file name when using the wËfile command to write the buffer contents into a file. U22794-J-Z125-6-76 289 ed, buffer and operating modes ed buffer When ed is invoked, a buffer is opened. If you have not entered a file name, the buffer will be empty. You can then fill it with text during your editor session. If you have named a file, a copy of the file is read into the buffer. During your editor session, you essentially process the contents of the buffer. Before you exit the editor again, you must decide whether you want to save the newly created or modified buffer contents by writing them to a file. If you wish to save the buffer contents, you use the w[Ëfile] (write) command to write the contents of the buffer back to the specified file (by default the one named when ed was invoked) and then exit the editor with the q (quit) or Q (Quit) commands or with the [END] key. If you do not wish to save the buffer contents, you can exit the editor without writing back the contents of the buffer with w. You do this by pressing Q or q twice. When you press q the first time, ed will issue a ? as a warning to prevent you from inadvertently deleting the buffer contents. The buffer will not be deleted unless and until you press q a second time. If you prefer, you can also enter Q or [END] instead of the second q. Operating modes ed provides you with two operating modes: command mode and input mode. ed enters command mode when it is called with ed[Ëfile]Ú. In command mode you specify a command in a line and confirm your input by pressingÚ. Input mode is activated by means of one of the following commands: a (append) i (insert) c (change) (see “ed commands” on page 293). In input mode, all the input characters which follow, including various non-printing characters (e.g. key codes of cursor keys), are written to the working copy in the buffer. ed does not accept any commands in input mode. If you wish, you can define a prompt for command mode (see option -p and ed command P) so that you can instantly detect the mode in which you are currently working. You leave input mode either by pressing [DEL] or by entering a period (.) in the first column and hitting Ú. When you press [DEL], ed normally ignores all input since the lastÚ and displays a ? as a warning. 290 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed, command structure Command structure For ed, there is a current line at all times. As a rule, the line last processed by a command represents the current line. If you do not specify another address in front of the commands, they will always refer to the current line. Most ed commands have the following structure: [range]ed-command[parameter...] Ú range The range you enter identifies the lines in the buffer to which the ed command is to be applied. One or two addresses can be specified in range: range = address The line identified by address is selected. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 range = address1,address2 address1,address2 identifies the range between the specified limits (inclusive). The search for both addresses begins at the current line, which is not changed until commands are executed. address2 must refer to a line that follows the line referenced by address1 in the buffer. Otherwise, ed reports an error. range = address1;address2 address1;address2 identifies the range between the specified limits (inclusive). The search for address1 begins at the current line. The new current line is set to the line identified by address1, and only then is address2 calculated. You can use this feature to define the starting line for forward and backward searches (see the section “Addresses” on page 292, // and /RE/ on the following page) . address2 must refer to a line that follows the line referenced by address1 in the buffer. Otherwise, ed reports an error. range not specified: ed assumes the default address for each command; this address is described for each of the ed commands. If ed requires no address but you have nevertheless specified one, ed reports an error. If you have specified more addresses than necessary, ed uses the last address(es) specified. U22794-J-Z125-6-76 291 ed, addresses Addresses Addresses are constructed as follows: Address Meaning . Current line $ Last line n nth line 'x The line marked with the letter x. x must be a letter in lowercase (see k command). /RE/ A simple regular expression RE enclosed in /.../ (see section “Regular POSIX shell expressions” on page 877addresses the first line containing a character string that matches the regular expression, searching forward from the current line. If ed does not find a match in any line, the search wraps around and continues from the beginning of the file until a match is found or the current line is reached again. If the regular expression RE contains the delimiter / or ?, this must be escaped using \. The characters \n in a regular expression do not match newline characters in the searched text! A regular expression may only appear once in range. Thus, /RE1/,/RE2/, for example, will only address the first line that matches /RE2/. // A null regular expression // addresses the line matching the regular expression last specified. ?RE? Like /RE/, except that the search begins at the current line and proceeds toward the beginning of the file. If the regular expression RE contains the delimiter / or ?, this must be escaped using \. addr[+]n nth line after the line identified by addr. addr[-]n nth line before the line identified by addr. +n n lines forward from the current line. -n n lines backward from the current line. [addr]+... 292 [addr]-... One line forward (+) or backward (-) from the line identified by addr. Each occurrence of + or - respectively increases or decreases the address specification by 1. Thus, ++ addresses the second line after the current line (2 lines forward). , A comma stands for the address pair 1,$ if followed by a command; if not, the last line is output. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed, command overview ; A semicolon stands for the address pair .,$ if followed by a command; if not, the last line is output. ed commands The following list includes a systematic overview of all ed commands that you can enter in the command mode. The detailed command description that follows is arranged in alphabetical order. Activate input mode a append append text after addressed line c change delete and replace i insert insert text before addressed line Output prompt in command mode P prompt use * as prompt Undo commands u undo undo most recent command Abort commands [DEL] --- abort execution of command Explain errors h help explain last error message H Help toggle help mode on and off. If help mode is on, error messages are printed for all subsequent ? diagnostics (see page 303) a append append text after addressed line c change delete and replace d delete delete lines from buffer i insert insert text before addressed line Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Modify text Output lines p print print addressed lines l list output with non-printing characters in alternative representation or as octal numbers address -- output addressed lines address/+n --umber output addressed lines n number print indicated lines with line numbering Ú --- output line following current line U22794-J-Z125-6-76 293 ed, command overview Output line numbers address= --- output addressed line number n number output lines with line numbering Move specified line ranges t transfer append a copy of addressed lines m move move lines to after addressed line Search and replace s substitute search and replace join join contiguous lines mark mark addressed lines Join lines j Mark linves k Process selected lines with commands g global apply command list globally to all lines that match the given /RE/ G Global apply interactive command list globally to all lines that match the given /RE/ v vice-versa like g, but for all lines that do not match /RE/. V Vice-versa like G, but for all lines that do not match /RE/. Change current file name f file-name change/display current file name Execute shell commands ! --- send command to shell for interpretation Read files into buffer e edit delete buffer and read named file into it E Edit clear buffer without warning and reload original r read read file into buffer Save buffer contents w write write buffer contents into file W write append buffer contents to file Quit the editor 294 q quit quit ed Q Quit quit ed without warning [END] --- quit ed U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed, command description Description of the ed commands The square brackets [] are not to be entered. They merely indicate that the entry enclosed within them is optional. As a rule, only one command may be entered per line. However, you can append the suffixes l, n, or p to the commands (with the exception of e, f, r, and w) if the functions described under l, n, and p are to be executed. [address]a text . (append) reads the text input and appends it to the line addressed in address. The current line is now either the last line of the inserted text or, if you have not entered any text, the addressed line. Address 0 is legal for this command: it causes the "appended" text to be inserted at the beginning of the buffer. The maximum number of characters that may be entered from a terminal is 2048 per line (including the newline character). address not specified: address = . [range]c text . (change) deletes the specified range and replaces these lines with thetext input. The current line is now either the last line of the entered text or, if you have not entered any, the line preceding the deleted lines. range not specified: range = .,. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 [range]d (delete) deletes the specified range. The line after the last line deleted becomes the current line. If the deleted lines were at the end of the buffer, the new last line becomes the current line. range not specified: range = .,. e[Ëfile] (edit) deletes the entire buffer and reads in a copy of the contents of the named file. If the contents of the buffer have been modified but not saved with w, ed prevents inadvertent deletion of the buffer by first issuing a ? as a warning. If you now enter e again, the old buffer contents are deleted without further comment. The number of bytes read is output provided you did not call ed with the -s option. The current line is the last line of the buffer. The specified file name file is remembered for possible use as a current file name in subsequent e, r, and w commands. If file is replaced by an exclamation point !, the rest of the line is interpreted as a shell command and executed. The output of the shell command is read into the buffer. A shell command that is preceded by an ! is not stored as the file name. U22794-J-Z125-6-76 295 ed, command description file not specified: file = current file name E[Ëfile] (Edit) behaves like edit, except that it overwrites the buffer without issuing a ? as a warning even if the buffer contents have been modified but not saved. file not specified: file = current file name f[Ëfile] (file) sets the current file name to file. The current file name is used by the commands e, E, r and w. file not specified: ed outputs the current file name. [range]Ëg/RE/commandlist (global) first marks all lines containing a character string which matches the regular expression RE. RE is a simple regular expression (see section “Regular POSIX shell expressions” on page 877). Then commandlist is executed for each line marked, with the current line being set to the next marked line in each case. A single command or the first in a commandlist must be entered in the same line as the g command. All lines in commandlist except the last one must end with \Ú; the last command itself withÚ. The commands a, i, and c with their associated input text are allowed. All lines in text must also be terminated with \ Ú. The period "." usually used to terminate input can be omitted from the last line of commandlist. An empty commandlist is equivalent to the p command. The g, G, v, and V commands are not permitted in the commandlist. The global command must not be combined with the ! command. range not specified: range = 1,$ [range]G/RE/ (Global) is the interactive variant of the g command. First, every line that matches RE is marked. RE is a simple regular expression (see section “Regular POSIX shell expressions” on page 877). The first of the marked lines is printed. At the same time, this line becomes the current line. You now have the option of specifying a command to be executed (other than a, c, i, g, G, v, or V). After the execution of that command, the next marked line is printed, and so on. 296 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed, command description A newline acts as a null command; an ampersand & causes the re-execution of the most recent command executed within the current invocation of G. Note that the commands input as part of the execution of the G command may address and affect any lines in the buffer. The G command can be terminated by pressing the [DEL] key. range not specified: range = 1,$ h (help) issues a short error message that explains the reason for the most recent ? symbol displayed on the screen. See Error for a list of possible error messages. H (Help) causes ed to enter a mode in which error messages are printed instead of the ? symbol for all errors that follow. It will also explain the previous ?, if any. You can deactivate the help feature by calling the H command again. The H mode is normally off. See Error for a list of possible error messages. [address]i text . (insert) inserts the given text before the line referenced by address. The last inserted line of text, if any, becomes the current line; otherwise, the addressed line does. This command differs from the append command only in the placement of the entered text. Address 0 is not legal. The maximum number of characters that may be entered from a terminal is 2048 per line (including the newline character). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 address not specified: address = . [range]j (join) joins all lines in the specified range into one line by removing the appropriate newline characters. If you have only specified one address, nothing happens. The new line becomes the current line. range not specified: range = .,. [address]kx (mark) marks the line referenced by address with the letter specified in x, where x must be in lowercase. The marker itself is not output. The marked line can then be addressed by using ’x (single quote x). The current line is unaffected. address not specified: address = . U22794-J-Z125-6-76 297 ed, command description [range]l (list), in contrast to p, outputs the specified range as follows: some non-printing characters are output in alternative representation (e.g. tab characters), the remaining non-printing characters are output as octal numbers. Overlength lines are folded into several lines, each terminated by the line continuation character \. Each line must end with $. An l command can be appended to any command other than e, f, r, or w. The following alternative representations are used: \\ \a \b \f \n \r \t \v Backslash (for distinguishing octal characters) Warning, Bell 1) Backspace 1) Form Feed Newline Carriage Return Tab Vertical tab 1) 1) These non-printing characters are supported on character terminals only (i.e. when the POSIX shell is accessed via rlogin) range not specified: range = .,. [range]maddress (move) re-positions the lines in the specified range after the line addressed by address. The last of the shifted lines becomes the current line. If you specify a value of 0 for address, the range is moved to the beginning of the file. If address falls within the range of moved lines, ed issues an error message. range not specified: range = .,. [range]n (number) prints the range of addressed lines, preceding each line by its line number and a tab character. The last line to be printed becomes the new line. The n command can be appended to any command other than e, f, r, or w. range not specified: range = .,. 298 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed, command description [range]p (print) prints the range of addressed lines. Non-printing characters are not output unchanged. Overlength lines are continued in the next line, i.e. are not identifiable as such. The current line is the last line printed. The p command can be appended to any command other than e, f, r and w. For example, dp deletes the current line and prints the new current line. range not specified: range = .,. P (Prompt) causes ed to use an asterisk * or the defined prompt string as a prompt in command mode (see option -p above). You can deactivate this mode again by calling P a second time. This mode is normally deactivated. q (quit) terminates ed. If you have changed the buffer contents since the last time the buffer was saved or overwritten, but have not yet written these changes to a file with w, ed outputs a ? as a warning (to prevent inadvertent deletions) and waits for further input. By entering [END], Q, or the q command a second time, you can now exit ed without further warnings and without saving the buffer. ! Caution! If you continue after the first q with actions that do not change the buffer contents, no new warning will be issued when you press q again. ed will be terminate without saving the buffer. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Q (Quit) terminates ed immediately without warning even if you have changed the buffer contents since last saving or overwriting and have not yet written these changes to a file with w. [address]r[_file] (read) reads the named file and inserts its contents after the line identified by address. The address 0 is legal for this command and causes the file contents to be written at the start of the buffer. If the read was successful, the number of bytes read is output unless you called ed with the -s option. The current line is the last line read in. The currently remembered file name is not changed to file unless you invoked ed without a file name and file is the very first file name mentioned since ed was invoked. If file is replaced by the ! character, the rest of the line is interpreted as a shell command and executed. The output of this command is then read. Such a command is not remembered as the current file name. address not specified: address = $ file not specified: file = current file name U22794-J-Z125-6-76 299 ed, command description [range]s/RE/replacement_string/[g][l][n][p][count] (substitute) searches each line in range for strings which match RE. RE is a simple regular expression (see section “Regular POSIX shell expressions” on page 877). On each line in which a match is found, strings that match RE are replaced by replacement_string. If ed does not find a matching string, it returns a ? to indicate an error. To delimit the regular expression RE from the s command and the replacement_string, any other character except the blank or newline can be used instead of /. The character selected is recognized as a delimiter by virtue of coming immediately after s. Afterwards, the current line is the line in which the last substitution took place. count Substitute for the countth occurence only of the RE found on each addressed line. g Globally substitute for all non-overlapping instances of the RE rather than just the first one. If both g and count are specified, the results are unspecified. l Write to standard output the final line in which a substitution was made. The line will be written in the format specified for the l (list) command. n Write to standard output the final line in which a substitution was made. The line will be written in the format specified for the n (number) command. p Write to standard output the final line in which a substitution was made. The line will be written in the format specified for the p (print) command. Metacharacters in the replacement string Metacharacters Meaning & is replaced by the string which matches regular expression RE in a successful search. \n is replaced by the character string matching the nth regular subexpression, delimited by\(...\), of RE where n is a decimal digit. If nested parenthesized subexpressions are present, n is determined by counting occurrences of \ from left to right. % is replaced by the replacement string from the most recent s command if replacement_string consists solely of the % character. The special meaning of these characters can be suppressed by preceding each of them with a backslash \. 300 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed, command description Splitting a line in the replacement string To split a line you can include an escaped newline character, i.e. \Ú, in replacement_string. This type of substitution command cannot be used in a commandlist with a g or v command. range not specified: range = .,. [range]ta copies the addressed range after the specified line a. 0 is allowed for a. The current line is the last of the copied lines. range not specified: range = .,. u (undo) nullifies the effect of the most recent command that modified anything in the buffer. The following commands can be undone: a, c, d, g, i, j, m, r, s, t, v, G, and V. [range]v/RE/commandlist (vice versa) causes commandlist to be executed on all lines containing no string that matches the regular expression RE. RE is a simple regular expression (see section “Regular POSIX shell expressions” on page 877). v functions identically to the global command g with the selection criterion reversed. v should not be combined with the ! command. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 range not specified: range = 1,$ [range]V/RE/ (Vice versa) is the interactive variant of the v command. You can use V to process all lines that contain no string matching the regular expression RE. RE is a simple regular expression (see section “Regular POSIX shell expressions” on page 877). V functions identically to the global command G with the selection criteria reversed. range not specified: range = 1,$ [range]w[Ëfile] (write) writes the specified range into the named file. The currently remembered file name is not changed if previously set. If the file name has not been set, file is used as the new current file name. The old contents of file are overwritten in the process. If the named file does not exist, it is created. The current line remains unchanged. After a successful write operation the number of characters written is displayed, provided you did not invoke ed with the -s option. If file is replaced by !, the rest of the line is interpreted as a shell command and executed. The standard input for the shell command is the range of addressed lines. Such a command is not remembered as the current file name. U22794-J-Z125-6-76 301 ed, command description range not specified: range = 1,$ file not specified: file = current file name [range]W[Ëfile] (Write) appends the specified range to the end of the named file. This command is the same as the w command above, except that w overwrites existing files. If file does not exist, it is created. address The line identified by address is output. [address]+num This command outputs the line that is num lines after the line identified by address. address not specified: address = . [address]= The line number of the line identified by address is output; the current line is not changed by this command. address not specified: address = $ !command The remainder of the line after the ! is interpreted and executed as a shell command. If an unescaped % character appears within the text of command, it is replaced by the remembered file name. !! causes the last command to be repeated. In both cases, the expanded command line is echoed. On completion of the command, ed is reactivated. The current line remains unaffected. This command must not be combined with g and v! Ú Entering Ú alone in the command mode causes the line after the current line to be printed. This is the same as specifying .+1p. You can use this feature to step through the buffer. The input of a command in command mode or a text line in input mode must be terminated by pressing the Ú key. [DEL] You can use the [DEL] key to interrupt a currently executing ed command or to cancel the entry of a line. ed will then respond by displaying a ’?’. [END] or [CTRL][D] or @@d The [END] key (or any of the key combinations) has the same effect as the q command. 302 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed If the closing delimiter of a regular expression or of a replacement string (e.g. a /) is the last character before a newline, you may omit that delimiter. In such a case, the addressed line is printed. The following pairs of commands are equivalent: 7. Juli 2009 Stand 11:58.29 s/s1/s2 g/s1 ?s1 s/s1/s2/p g/s1/p ?s1? Working with ed scripts Since ed reads commands and text that is to be inserted from standard input, you can redirect the input to a file and have ed read the file instead. Thus $ ed - file < ed_scriptfile > output edits the named file and processes it with the ed commands stored in the specified ed_scriptfile. The -s option suppresses default output of message texts to the screen. The advantage of using ed scripts is that they allow you to reproduce specific command sequences at any time and use them as often as required. Furthermore, this feature enables you to perform these tasks in a background process while you continue working at the terminal without interruptions: $ ed file < ed_scriptfile& If your ed script contains errors, ed will exit on encountering the first error. Exit status 0 >0 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Error if successful if ed is called incorrectly or if a script is aborted due to incorrect use of ed commands. If you do not enter a blank between option p and string in the ed call or if you forget to enter the string: ed: -p arg missing If you make a mistake when entering ed commands: ? This means that the command contains syntax errors. ?file The indicated file is not available or cannot be read. U22794-J-Z125-6-76 303 ed More detailed information can be obtained by using the h and H commands. The commonest error messages are listed below. They are all self-explanatory: line out of range warning: expecting 'w' no space after command unknown command bad range cannot open input file illegal or missing delimiter illegal suffix illegal or missing filename no match File ed.hup Data is saved in this file if ed receives the SIGHUP signal (see section “kill terminate or signal processes” on page 444). /var/tmp If this directory exists, it is used as the directory for storing the temporary work file. /tmp /tmp is the directory used to store the temporary work file if the TMPDIR variable is not assigned the name of an existing directory and var/tmp does not exist. Variable TMPDIR If this variable is set and is not null, it is used instead of /var/tmp as the directory for storing the temporary work file. HOME Determine the pathname of the user’s home directory. Locale The following environment variables affect the execution of ed: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. 304 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files) and the behavior of character classes within regular expressions. LC_CTYPE also governs which characters the ed command l treats as non-printing. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Example of an ed script: The first three lines of a file are to be replaced by one line with the text "Addresses", and all occurrences of the word "Street" are to be replaced by "Plaza". Contents of the edscript: 1,3c Addresses . 1,$s/Street/Plaza/g w Processing of a file with commands from edscript: $ ed file < edscript When ed reads commands from a file instead of the keyboard, the editor is exited as soon as ed encounters the first incomprehensible command. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example 2 Example of a here script (see sh): In a set of files that are to be passed as command-line arguments to the script xy, the first three lines are to be replaced by one line with the text "Addresses", and all occurrences of the word "Street" are to be replaced by "Plaza". Contents of the script file xy: for i in $* do ed $i << scrend 1,3c Addresses . 1,\$s/Street/Plaza/g w scrend done U22794-J-Z125-6-76 305 ed Processing of the files text1, text2 and text3 with script xy: $ sh xy text1 text2 text3 The string << scrend after the ed call causes the shell to transfer the text up to the string scrend as input to ed. The second string scrend must exist as a single word in a line, without leading blanks. The special meaning of the $ symbol must be escaped with a \ in the address specification 1,$. This is because the shell would otherwise interpret the following s as the name of a shell variable. Example 3 The following example demonstrates and explains a number of ed commands: $ ed - Call ed P - Output prompt * in command mode *a - Append to current line, in this case beginning of file line1 - Input text line2 line3 . - Terminate input mode *1,$p - Output line 1 through to last line line1 line2 line3 *p - Output current line (= last line processed) line3 *n - Output current line with line number 3 line3 *1,$n - Output line 1 through to last line with line numbers 1 line1 2 line2 3 line3 *2c - Replace line 2 with following input including tabs line2 ¯ line2 ¯ line2 another line2 . - Terminate input mode *p - Output current line another line2 *1,$n - Output line 1 through to last line with line numbers 1 line1 2 line2 line2 line2 3 another line2 4 line3 *4s/3/4 - In line 4, search for the character 3 and replace it with 4 line4 *n - Output current line with line number 4 line4 *1,$s/l/L/g - Search from line 1 through to last line for all l characters and replace them with L 306 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ed 7. Juli 2009 Stand 11:58.29 *1,$p Line1 Line2 Line2 another Line2 Line4 *2l Line2 Line2>Line2>Line2 * *2r file - Output line 2 with non-printing characters as mnemonic overstrikes. - Read the contents of file into the buffer after line 2 and output the number of characters read in. file must already exist! 46 *1,$n - Output line 1 through to last line with line numbers 1 Line1 2 Line2 Line2 Line2 - This line and the two which follow are 3 line1 of file out of file 4 line2 of file 5 last line of file 6 another Line2 7 Line4 *6,7c - Replace lines 6 to 7 by the following input very last line . - Terminate input mode *1,$n - Output line 1 through to last line with line numbers 1 Line1 2 Line2 Line2 Line2 3 line1 of file 4 line2 of file 5 last line of file 6 very last line *q - Attempt to quit editor with q ? - Warning *h - Explain question mark warning:expecting 'w' - Explanation: w command expected by ed (to save contents of the buffer) was not entered *w exp - Write the contents of the buffer to the file exp 85 - Number of characters written is output *q - Quit editor $ - Shell prompt © cognitas GmbH 2001-2007 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 - Output line 1 through to last line See also ex, grep, sed, sh, stty, umask, vi Tables and directories, Regular expressions U22794-J-Z125-6-76 307 edt edt Built-in sh command screen-oriented editor EDT (BS2000) edt calls the BS2000 file editor , see the EDT (BS2000/OSD) manual [7]. EDT V17.0 and higher is called in compatibility mode. edt is the editor for block-mode terminals. If you are working with character-mode terminals, you can use ex or vi for example. You can use this command and the EDT functions to copy files from the POSIX file system to the BS2000 and vice versa. Syntax edt[Ë-k][Ë-iindex]Ëfile -k Prior to editing, the file contents are converted from ASCII to EBCDIC code. Before being written back to the file, the contents are recoded to ASCII. You can use this option if you wish to use edt to process an ASCII-coded file. -iindex This option is required if files containing more than 9999 lines have to be read. The product * 0.0001 gives the number of the first line and the step size used between line numbers. If there is no specification then =10000, i.e. the number of the first line and the step size value are both 1. Within EDT itself, the EDT statement renumber can be used to perform renumbering. file File name of the POSIX file. You may specify one file only. If the specified file does not yet exist, the empty work file 0 is opened. Hint EDT can create, read in, copy, write back and close POSIX files. The @XOPEN, @XCOPY, @XWRITE and @CLOSE statements are available for this purpose (see the manual “EDT (BS2000/OSD)” [7]). To write the opened POSIX file back to the BS2000 file system, use the EDT statement @write‘ ‘ when in EDT level 0. You can terminate EDT with @HALT (write the opened POSIX file back to the POSIX file system in interactive mode) or @RETURN (unconditionally write the opened POSIX file back to the POSIX file system in interactive mode). Use @WRITE at EDT level 0 to write an opened UFS file back (to UFS). Blank lines in the file are displayed as lines with a length of 1 (the character X'0D'). They are subsequently converted back to blank lines on saving the file. The tab character ('\t') is not expanded to the corresponding number of spaces. The edt command cannot be used in a pipe. 308 U22794-J-Z125-6-76 Error edt edt cannot be used within a pipe The edt command was incorrectly used in a pipe. edt cannot be used within a forked process The edt command was entered in a subshell. This is not allowed. edt: file file open for read failed You do not possess read permission for file. 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command *** read only *** in the edt message line The file which you wish to edit is write-protected. edt: file file open for write failed, permission denied You do not have write permission. The following messages are then displayed: edt: edited file(s) not saved! edt: terminate edt? reply (y=yes; n=no)? edt: file file open for write failed, no such file or directory The path does not exist. The following messages are then displayed: edt: edited file(s) not saved! edt: terminate edt? reply (y=yes; n=no)? edt: file file write: UFS file system failed, no space Not enough space in the POSIX file system to write the file. The following messages are then displayed: edt: edited file(s) not saved! edt: terminate edt? reply (y=yes; n=no)? If, for the reasons above, the file cannot be written, the user may stay in EDT and take the necessary action to save the file, for example change the write permission or use @WRITE‘file‘ to save the file. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example The POSIX file /usr/home/file.pos is to be saved in the BS2000 file system as the BS2000 file file.bs2. $ edt /usr/home/file.pos ..... @WRITE ´file.bs2´ ..... U22794-J-Z125-6-76 (EDT statement) 309 egrep egrep search a file with an ERE pattern egrep reads lines from one or more files or from standard input and compares these lines with the specified patterns. Unless told otherwise (by options), egrep copies every line that matches one of the patterns to standard output. egrep permits the use of extended regular expressions in the specified pattern (see section “Regular POSIX shell expressions” on page 877). If you specify more than one input file, the relevant file name will be displayed before each output line. Syntax Format 1: egrep[Ë-bchilnvy]Ë-eËpatternlist[Ëfile...] Format 2: egrep[Ë-bchilnvy]Ë-fËpatternfile[Ëfile...] Format 3: egrep[Ë-bchilnvy]Ëpatternlist[Ëfile...] The formats are described together since the patterns which egrep uses to compare the input lines are specified either via patternlist or using the option -e patternlist or -f patternlist. You must specify one of these arguments. Two of them or all three together are not permitted. No option specified egrep outputs all lines that match at least one of the patterns specified in patternlist. If you specify more than one input file, each output line will be preceded by the name of the file in which the line was found. option -b (block) Each output line is preceded by the number of the block in which it was found. Each file is made up of 512-byte blocks which are numbered consecutively from 0. The -b option is sometimes useful in locating disk block numbers by context (see the offset argument for the od command, for example). -c (count) egrep outputs only the number of lines found (i.e. the lines that egrep would have displayed without the -c option, see Example 4); the lines themselves are not displayed. -h (hidden) When searching multiple files, egrep does not write the file name before each output line. -i or -y (ignore) egrep does not distinguish between uppercase and lowercase -l (list) egrep simply outputs the names of files that contain at least one of the matching lines. (These are the lines that egrep would output if the -l option were omitted, see Example 5.) Each file name is printed just once. The lines themselves are not displayed. -n (number lines) Each output line is preceded by its line number in the relevant input file. Line numbering starts at 1. If egrep is reading from standard input, the line number refers to the standard input. 310 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc egrep -v (v - vice versa) egrep outputs all the lines which correspond to none of the specified patterns. Together with option -c: egrep only outputs the number of such lines. Together with option -l: egrep only outputs the names of the files containing such lines. -eËpatternlist (expression) You will need this option if the first expression in patternlist begins with a minus sign. When used in conjunction with the -e option, a patternlist of this type is not interpreted as an option itself but as a list of patterns which egrep is to use in searching for matching input lines. -fËpatternfile (file) egrep reads the pattern list from the file named patternfile. Each line in patternfile is interpreted as an extended regular expression. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 patternlist A list of extended regular expressions that egrep is to use in searching for matching input lines (see section “Regular POSIX shell expressions” on page 877). Individual regular expressions must be separated by the newline character. Any newline character within patternlist is interpreted like an OR separator (|) in an extended regular expression. Regular expressions of the type (r|s) can also be specified without the parentheses: r|s (see Example 1 on page 313). If patternlist contains newline characters or other characters that have a special meaning for the shell, you must enclose the specified patternlist in single quotes: ’patternlist’. If the first expression in patternlist begins with a minus sign, you must specify patternlist along with the -e option or terminate the option list with -- to prevent the patternlist from being interpreted as an option itself. file Name of the file that egrep is to scan. You may name any number of files. file not specified: egrep reads its input from standard input. grep, fgrep and egrep The grep, fgrep and egrep commands perform similar functions and are largely identical in terms of usage. The following section lists the most important differences between these commands. grep processes simple regular expressions. Only one regular expression may be specified in each call. U22794-J-Z125-6-76 311 egrep fgrep processes strings only. However, you may specify several strings in one call. The strings can either be entered directly in the command line, separated by newline characters, or passed to fgrep from within a file. fgrep is fast and compact and can search for a large number of strings. All specified strings are searched for in each individual line. egrep processes extended regular expressions. Among other things, these include all simple regular expressions with one exception: the \(...\) construct used in simple regular expressions does not have a special meaning in extended regular expression syntax and is hence not processed by egrep. Several regular expressions can be specified together, separated by newline characters. egrep interprets these newline characters as an OR operator (the vertical bar character; see Tables and directories, Regular POSIX shell expressions). The regular expressions can either be specified directly in the command line or passed to egrep via a file. Exit status Locale 0 Matching lines found 1 No matching lines found >1 Syntax error or "File cannot be opened". This exit status remains valid even if lines have been found in other input files. The following environment variables affect the execution of egrep: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files) and the behavior of character classes within regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH 312 Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc egrep Example The files customer1 and customer2 will be used as a basis for all following examples. Their contents are given below: customer1: 080685 120387 180588 999.98 1240.25 330.87 20 Units 3 Units 1 Units Item Item Item 038 023 332 Nicolson Ltd. Robinson Ltd. Robinson Ltd. customer2: morrow lance, 86 sherwood street, london w1 robinson peter, 16 garden hill, london ec3 Example 1 Output lines that match a pattern (without an option and with option -i): $ egrep Robinson customer1 customer2 customer1:120387 1240.25 3 Units customer1:180588 330.87 1 Units Item Item 023 332 Robinson Ltd. Robinson Ltd. If you also wish to find lines containing the word robinson in lowercase you enter: $ egrep -i robinson customer1 customer2 customer1:120387 1240.25 3 Units Item 023 Robinson Ltd. customer1:180588 330.87 1 Units Item 332 Robinson Ltd. customer2:robinson peter, 16 garden hill, london ec3 More complicated patterns can be set up with the help of regular expressions, e.g.: Display lines which contain the string Nicolson or Robinson: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ egrep '(Nicol|Robin)son' customer1 customer2 customer1:080685 999.98 20 Units Item 038 customer1:120387 1240.25 3 Units Item 023 customer1:180588 330.87 1 Units Item 332 Nicolson Ltd. Robinson Ltd. Robinson Ltd. Instead of the regular expression (Nicol|Robin)son you could also use the following regular expression: (Nicolson|Robinson) In this case you can leave out the parentheses; Nicolson|Robinson The OR operator (|) in the last expression Nicolson|Robinson could also be replaced by a newline character (see Example 2). U22794-J-Z125-6-76 313 egrep Example 2 Using several patterns (without an option and with option -f): $ egrep '^1 > 1$' customer1 customer2 customer1:120387 1240.25 3 Units Item 023 Robinson Ltd. customer1:180588 330.87 1 Units Item 332 Robinson Ltd. customer2:morrow lance, 86 sherwood street, london w1 Alternatively, you could write both patterns into a file called names (each pattern in a separate line) and then call egrep as follows: $ egrep -f names customer1 customer2 The same result is obtained when the newline character that separates the patterns ^1 and 1$ is replaced by the OR operator: $ egrep '^1|1$' customer1 customer2 Example 3 Output lines that match none of the specified patterns (option -v): $ egrep -v '^1 > 1$' customer1 customer2 customer1:080685 999.98 20 Units Item 038 Nicolson Ltd. customer2:robinson peter, 16 garden hill, london ec3 The above call thus yields all lines that neither begin nor end with 1. The same result can also be obtained with the following call (see Example 2): $ egrep -v '^1|1$' customer1 customer2 Example 4 Display the number of lines found (option -c): To begin with, the number of lines that start with 1 are to be output for each input file. $ egrep -c '^1' customer1 customer2 customer1:2 customer2:0 The number of lines that do not begin with 1 are now to be displayed. $ egrep -c -v '^1' customer1 customer2 customer1:1 customer2:2 314 U22794-J-Z125-6-76 Example 5 Display file names only (option -l): Display file names only (option -l): The names of files containing lines that begin with 1 are to be output first. $ egrep -l '^1' customer1 customer2 customer1 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc egrep The names of files containing lines that do not start with 1 are displayed next. $ egrep -l -v '^1' customer1 customer2 customer1 customer2 Example 6 Display found lines with relevant line numbers (option -n): $ egrep -n -i robinson customer1 customer2 customer1:2:120387 1240.25 3 Units Item 023 Robinson Ltd. customer1:3:180588 330.87 1 Units Item 332 Robinson Ltd. customer2:2:robinson peter, 16 garden hill, london ec3 ed, fgrep, grep, sed Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 315 env env set environment for command execution The env command can be used to display current environment variables and their values or to set them for the execution of a specific command. env inspects the current environment, modifies it according to the assignment in name=value, and then executes the command in the modified environment. The existing specifications for name and value are overwritten by the new ones, and the new arguments are merged into the inherited environment before the command is executed. The valid environment for the execution of command thus consists of the new specifications together with any unmodified environment variables. If no command is specified, env prints the resulting environment. Syntax env[Ë-i|Ë-][Ëname=value]...[Ëcommand[Ëarg...]] –i|ËThe original environment is ignored; command is then executed with exactly the environment specified by the arguments. The i option corresponds to the old - option, which will continue to be supported. name=value name specifies the name of a variable that is to be valid for command. value is the value of name which is to apply to command. command Name of the command or shell script which you would like to have executed in the defined environment. arg Argument, e.g. positional parameters or user-defined variables which can be passed to command. Exit status 0 The env utility was completed successfully 1-125 Error Variable 316 126 The utility specified by utility was found but could not be invoked. 127 The utility specified by utility could not be found. PATH Determine the location of the utility. If PATH is specified as a name=value operand to env, the value given will be used in the search for utility. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc env Locale The following environment variables affect the execution of env: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example 1 Output the current values of environment variables: $ env _=/usr/bin/env TTY=/dev/term/004 IO_CONVERSION=NO PATH=/usr/bin:/opt/bin::/etc:/usr/sbin TERM=BLOCK HZ=100 LOGNAME=TESTUSER PROGRAM_ENVIRONMENT=SHELL HOME=/TESTUSER TZ=MEZ-1MSZ-2,M3.5.0/02:00:00,M9.5.0/03:00:00 MAIL=/var/mail/TESTUSER SHELL=/sbin/sh USER=TESTUSER LANG= U22794-J-Z125-6-76 317 env Example 2 Output the modified values of environment variables: $ env PATH=$HOME/proz _=/usr/bin/env TTY=/dev/term/004 IO_CONVERSION=NO PATH=/TESTUSER/proz TERM=BLOCK HZ=100 LOGNAME=TESTUSER PROGRAM_ENVIRONMENT=SHELL HOME=/TESTUSER TZ=MEZ-1MSZ-2,M3.5.0/02:00:00,M9.5.0/03:00:00 MAIL=/var/mail/TESTUSER SHELL=/sbin/sh USER=TESTUSER LANG= The PATH environment variable has been modified. Example 3 Output modified values of environment variables using the - option: $ env - PATH=$HOME/proz PATH=/TESTUSER/proz The original environment is ignored. Example 4 Invocation of the file ardor, located in /TESTUSER/SAYINGS, i.e. in a subdirectory of the HOME directory. Contents of file ardor: echo "$1 $2 $3 $4 $2 $3 $1 love $4!" Now call ardor from any location in your file tree with the arguments I know that you: $ env PATH=$HOME/SAYINGS ardor I know that you I know that you know that I love you! With the new definition of the PATH variable, you effectively define the location where the entered command is to be sought (the file ardor in our case), i.e. in a subdirectory of the HOME directory, which you specify with the value of the variable HOME ($HOME). The character strings I, know, that, and you are passed as arguments to the positional parameters $1, $2, $3 and $4. The contents of ardor are correctly executed here because echo is a built-in command of the sh shell. Due to the change in the PATH variable, all POSIX commands in /usr/bin, /usr/sbin or /opt/bin can no longer be found. To enable the execution of POSIX commands again, the PATH variable must be modified as shown in the example below. 318 U22794-J-Z125-6-76 Example 5 Call the file delcopy, which is located in the directory /TESTUSER/proc. This file contains a script that compares two files and deletes one of them if both files are identical. Contents of the file delcopy: if cmp -s $1 $2 then rm $2 fi 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc env Call the delcopy file from any location in your file tree with the arguments file1 and file2: $ env PATH=$PATH:$HOME/proc delcopy file1 file2 In this case, the new path is appended to the original one. This ensures that the delcopy script can be executed along with all SINIX commands contained in it. If only the path for delcopy were specified, the following error message would be issued. /TESTUSER/proc/delcopy: cmp: not found sh, set, exec profile, environ [12] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 319 eval eval Built-in sh command construct command by concatenating arguments The POSIX shell built-in eval can be used to pass command-line arguments to the sh shell for execution. The shell evaluates these arguments and then executes them as commands. The specified command-line arguments are thus evaluated twice by the shell: – First, when the shell processes the eval command line. – Second, when the processed command-line arguments are executed by the shell as commands. Each command-line is processed by the shell before execution. When do you need eval? The shell processes each command line in a number of steps (see section “Execution” on page 64), interpreting specific metacharacters in each processing step. The original command line may be modified by the individual processing steps. If, for example, the shell replaces a variable with its value or a command with its output, metacharacters may occur in the command line which may not be interpreted by the shell in subsequent processing steps. The shell built-in eval makes sure that metacharacters left by the previous step are interpreted in the following step (see also Examples on page 321). Syntax evalË[argumentË...] argument Any string delimited by blanks or tabs. The last argument must be terminated by a command separator. You may specify any number of arguments with at least one blank or tab between them. The specified arguments are executed by the shell as a command. Locale 320 The following environment variables affect the execution of eval: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command eval LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 The following command line cannot be executed as intended unless eval is used: $ cmd='date;echo name' $ $cmd sh:date;echo: not found $ eval $cmd Mon Mar 09 15:46:02 MEZ 2009 name To begin with, the shell replaces the cmd variable with its value. After the value has been substituted for the variable, the shell no longer recognizes the colon as a command separator. Calling eval causes the shell to interpret the semicolon as intended, since the $cmd argument is processed twice, i.e. rescanned by the shell. Example 2 The shell script evaltest will be used to demonstrate how the eval command is processed by the shell. The script file has the following contents: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 set -x loginname=max for i in 1 2 3 4 do eval group$i=$loginname$i eval echo \$group$i done set -x causes the shell running the shell script to write the commands processed to standard error output before executing them. On executing this shell script, you will receive the following output on the screen (without the line numbers): $ sh evaltest 1 + loginname=max 2 + eval group1=max1 3 + group1=max1 4 + eval echo $group1 5 + echo max1 6 max1 : This example shows only what is output the first time the loop is run. U22794-J-Z125-6-76 321 eval Built-in sh command Line 2 shows how the first eval command line is processed: here the shell has substituted the value 1 for $i and the value max for $loginname. eval must be invoked as the shell does not recognize the equals sign as an assignment operator the first time the loop is run. The shell executes an assignment only if the variable name (i.e. the string in front of the equals sign =) begins with a letter or the underscore character _ and contains letters, numbers and underscores only. group$i is an illegal variable name as it contains the dollar character. Line 3 shows that the assignment is made. When the command-line arguments are interpreted by the shell a second time, the equals sign is interpreted as intended, since the argument preceding the = sign represents a legal name for a shell variable. Line 4 demonstrates how the second eval command line is processed: the shell has substituted the value 1 for the positional parameter $i and removed the escape character \ preceding the $. eval is required in this case to ensure that the shell replaces the group1 variable by its value. Line 5 shows how the echo command is processed. Here, the shell has substituted the value max1 for $group1. Line 6 contains the output of the echo command. See also 322 set U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex ex command and display editor ex is a line-based text editor. Only users who have accessed the POSIX shell via rlogin can use ex (except in line mode). i ex offers you various operating modes: ● In the ex input mode you enter text directly. ● In the ex command mode you enter commands. Among other things, commands enable you to: – position the cursor – search for (and replace) text patterns with the aid of regular expressions – switch to another file – invoke a shell You also have the option of switching from the line editor ex to the screen editor vi. Layout of this description Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The description of how to call ex on POSIX shell level is followed by the sections: Functionality of ex – Operating modes of ex – Saving the editor buffer and quitting ex – Presetting ex – Current and alternate files – Regular expressions – Replacement strings – Buffers – Error and signal handling ex commands – Addressing – Parameters – Commands ex options U22794-J-Z125-6-76 323 ex Syntax ex[Ëoption]Ëfile... option -s (silent) All interactive output of the editor is suppressed. The -s option must be set when ex is to read its commands from a command script. The -s option has replaced the old - option. -tËtag (tag) ex loads the file containing the tag for editing and positions the tag definition under the cursor at the center of the screen. The tags file containing the search strings for the definitions must be in the same directory. This option is typically used by C programmers to quickly locate the definition of a function or macro on calling the editor. The tags file needed for this purpose must first be built with the ctags command. -rËfile (recover) Restores the ex session in which you were editing file if ex or the system crashed during your session. Changes that are only in the editor buffer are not copied to the edited file after a system or ex editor crash. POSIX does, however, try to save the buffer contents by creating a copy of it, if possible. file is recovered, including any changes made prior to the crash, and is retrieved into the vi buffer. You can now continue editing the file or save the changes in another file. -L Lists the names of all files saved following an editor or system crash. -wËn Sets the value of the ex window option (see page 349) to n. -R (readonly) The named file is opened in readonly mode. This mode prevents the original file from being accidentally overwritten, but allows you to write the buffer contents to a file with another name. ! Caution! The file can still be overwritten with w! in the ex command mode. -v (vi) Invokes the vi editor. A detailed description of vi is provided in this manual (see page 803). -cËcommand Positions the editor at a specific line of the file to be edited or executes an ex command when ex is invoked. If you position the editor at a line, the selected line will be displayed in the center of the screen. By contrast, if you have an ex command executed, the editor will be positioned at the last line of the file after executing the command, unless the ex command you specify (e.g. search) positions the editor itself. command not specified: The ex editor is positioned at the end of the file. 324 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex 7. Juli 2009 Stand 11:58.29 command specified: command may be specified as a line number (n), a search command (/pattern), or any other ex command (see “Commands” on page 334). The specified command is executed on invocation of ex: n n must be an integer. ex is positioned to the nth line of the file. /pattern ex is positioned to the first line containing pattern. If the pattern you specify includes metacharacters, you must escape them to protect them from being interpreted by the shell. ’ex-command’ or "ex-command" ex-command can be any ex command. The ex command must be quoted (using single or double quotes) in order to prevent it from being interpreted by the shell. If the editor is not already positioned as a result of an ex command, ex will be positioned to the last line of the file. Example When ex is called with: ex -c /tuesday appointments the file appointments is opened, and the cursor is positioned at the first line that contains the word tuesday. file file not specified: ex opens an empty buffer into which you can write your text. The contents of this buffer are not assigned a name until you write them back (with w) to a file or assign a name explicitly using the f command. ! Caution! If your file contains null characters, ex will discard them when reading in the file. No null characters appear in files written by ex. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Name of the file that you wish to edit. If you specify a number of files, these files will be processed in the order in which they are listed. The ex command n can be used to switch to the next file. U22794-J-Z125-6-76 325 ex Functionality of ex ex always works on a buffer, not on files. When you start an ex session, a working copy of the file you are editing is read into the editor buffer. All the editing changes you make are initially performed in this buffer and are not saved until you use the w (write) command to copy the buffer contents back into the original file. Once you have done this, you can quit ex using the q command. If you wish to exit the ex editor without writing back the changes to the original file, you must enter q!. Null ASCII characters (see section “ASCII character set (ISO 646)” on page 889) are discarded in input files and thus cannot appear in output files. Operating modes of ex ex offers you two file editing modes: – the ex command mode, and – the ex input mode. You can also switch from ex to the vi editor, which provides you with additional operating modes (for more details see “vi modes” on page 808). When ex is invoked, it comes up in command mode, as indicated by the prompt : displayed on the screen. The commands a (append), i (insert), and c (change) can be used to switch to the input mode, which enables you to add or modify text in the buffer (see “Commands” on page 334). In input mode, all subsequent input characters, including various non-printing characters, are written into the buffer. Commands are not interpreted as such. You can exit from input mode by entering a period (.) in the first column and then pressing . Saving the editor buffer and quitting ex ex must be in command mode to save the editor buffer or to quit the ex editor. Use the following command to save the contents of your editor buffer to the file edited or that specified: w[Ëfile] (write) The contents of the editor buffer are saved to the file specified. file not specified: The contents of the editor buffer are written back to the edited file. 326 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex You can quit ex using one of the following options: q (quit) Quit ex. This works only if the editor buffer has not been modified at all or if the modified editor buffer has been saved to a file. q! (quit) Quit ex. Unsaved modifications made to the editor buffer are not saved. x Quit ex and write the modified editor buffer to the edited file. wq[Ëfile] (write and quit) Quit ex and write the modified editor buffer to the file specified. file not specified: The contents of the editor buffer are written to the edited file. ! Caution! ex does not issue a warning if you place text in named buffers and do not save it before exiting the editor. The text is irretrievably discarded. Presetting ex The ex editor can, to some extent, be adapted to suit your requirements and working habits. This entails using the ex command se (set), which allows you to set or change specific options (see “ex options” on page 345). The changes you make remain in effect for the current session. Details on how to change default settings permanently can be found in the vi command description (see page 803). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Current and alternate file The file (or its copy) being edited by ex at any given moment is referred to as the current file. The alternate file is the file most recently mentioned in an editing command. If you switch to the alternate file, the file you switch from becomes the new alternate file. When specifying files, you can use the % character for the current file and the # character for the alternate file. These characters are replaced in file names by the names of the current file and the alternate file, respectively. Example w %.bak backs up the current file to a file with the same name but with the extension .bak. U22794-J-Z125-6-76 327 ex Regular expressions The interpretation of metacharacters in regular expressions depends on whether or not the magic option has been set for the ex editor (see “ex options” on page 345). When magic is set: character An ordinary character stands for itself. The following are metacharacters, not ordinary characters: ^ (caret) at the beginning of a pattern $ (dollar sign) at the end of a pattern * (asterisk) anywhere except at the beginning of a pattern . (period) at any position in a pattern [ (left square bracket) at any position in a pattern ~ (tilde) at any position in a pattern Metacharacters have special meanings and must be escaped with a backslash \ if they are to lose their special meanings. ^ ^ at the beginning of a pattern stands for the beginning of the line. $ $ at the end of a pattern stands for the end of the line. . stands for any one character. \< \> \< matches the beginning of a word. The word must begin with a letter, digit, or underscore and be preceded by the beginning of the line or a character other than the above. \> matches the end of a word. [string] Any character contained in string, where string is not a sequence of blank characters. The following characters have special meanings within string: – a dash - between a pair of characters defines a range, e.g. [a-z] matches a, z, and all the characters which come between them in the ASCII collating sequence. – if a caret ^ is the first character in string, it causes the construct to match any characters not included in string. If these characters are escaped by a backslash, they lose their special meanings. 328 * Zero, one or more occurrences of the regular expression preceding the * character. ~ Matches the replacement string used in the last s command (substitute, see “Commands” on page 334). U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex \(pattern\) A regular expression pattern can be enclosed in parentheses escaped by backslashes. This serves only to identify them for substitution actions (see Replacement strings below). rs A sequence of two regular expressions r and s is a regular expression in itself. rs matches all strings which consist of a string matching r followed by a string matching s. When nomagic is set: If nomagic has been set, the only characters that have special meanings are: – caret ^ at the beginning of a pattern – dollar $ at the end of a pattern, and – backslash \. The following characters only have a special meaning if they have been escaped by a preceding backslash \: – period . – asterisk * – left square bracket [ – tilde ~ Replacement strings The ampersand character & (with a preceding backslash, i.e. \&, if nomagic is set) in the replacement string stands for the text matched by the pattern, i.e. the text to be replaced. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The tilde ~ (\~ if nomagic is set) is replaced by the replacement string used in the previous s (substitute) command. The sequence \n, where n is an integer, is replaced by the text that is matched by the pattern enclosed in the nth set of parentheses \(...\). If the replacement string includes the sequence \u or \l, the character that immediately follows \u (upper) or \l (lower) in the replacement string will be converted to uppercase (for u) or lowercase (for l) if this character is a letter. The sequence \U or \L converts into uppercase or lowercase all letters until the end of the replacement string or until the sequence \E or \e is encountered. U22794-J-Z125-6-76 329 ex Buffers ex uses one unnamed and 26 named buffers, named a through z. You can use these buffers to copy text with ya (yank), to save deleted text with d (delete), and to subsequently retrieve this text with pu (put). The d, pu, and ya commands use the unnamed buffer unless you explicitly name a buffer. In other words, if you do not specify a buffer for a delete operation, for example, the material you delete will be saved in the unnamed buffer. You can save blocks of text in up to 26 buffers. The buffers are designated in either lowercase or uppercase letters from a-z (or A-Z). If you use lowercase letters, the old contents of the buffer will be overwritten by the new text, i.e. the old contents are deleted. If you use uppercase letters, the old buffer contents are not overwritten; the new text is appended to the old one instead. Error and signal handling When an error occurs during an ex session, ex sends the BEL character (acoustic signal; see section “ASCII character set (ISO 646)” on page 889) to the terminal and prints an error message. If an interrupt signal is received, ex returns to command mode, allowing you to enter a new ex command. If the editor input is from a file, ex exits at the interrupt signal. 330 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, addressing Entering commands Unlike most vi commands, which are interpreted and executed by vi immediately, ex commands must be "dispatched" by pressing the key. Command lines which start with double quotes " are ignored. This means that you can use lines of this kind to insert comment lines in a command script. Addressing An address is used to specify a particular line. Some ex commands expect one or more addresses as input. The specified line or line range (an inclusive range of all lines from the first address to the second) is then processed by the ex command. For ex, there is at all times a current line. This is explicitly addressed by a period (.). As a rule, the current line is the line last processed by a command or the line to which the editor has been explicitly positioned (e.g. by a search command). Addresses must be separated from one another by a comma or a semicolon. Such address lists are evaluated by ex from left to right. – When a semicolon (;) is used as a separator, the current line is set to the value of the first address before the second address is interpreted. – When a comma (,) is the separator, all addresses are calculated relative to the current line. The current line is not changed until the command is executed. © cognitas GmbH 2001-2007 address . Current line of the buffer. $ Last line of the buffer. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 If more addresses are given than the command requires, then all but the last address (when a line is expected) or the last two addresses (if a range is expected) are ignored. When a command requires two addresses, the first line that is addressed must precede the second one in the buffer. If you do not specify any address (null address), ex will use the current line by default. n nth line in the buffer. The lines are numbered sequentially from 1. ’x The line marked with the letter x, where x must be a lowercase letter (see “Commands” on page 334, ma or k). ’x is the address of the marked line. Before ex executes a movement command, the current line is marked. You can return to it with ’ ’ (2 single quotes). U22794-J-Z125-6-76 331 ex, addressing /RE/ A simple regular expression enclosed in /.../ (see section “Regular POSIX shell expressions” on page 877) addresses the first line which contains a character string which matches the regular expression, searching forward from the current line. If necessary, ex wraps around from the end of the buffer to its start to continue the search (see “ex options” on page 345, wrapscan). If the line matching RE is only to be printed, the second / may be omitted. RE not specified: The previous specified pattern is used. ?RE? As RE, but searching backward. +n -n If an address starts with a plus or minus sign followed by a decimal number n (optional), the line that lies n lines after (+) or before (-) the current line will be addressed. Thus, .+3, +3 and +++ have the same effect. adr+ adrIf an address ends with a plus or minus sign, the line that is located one line after (+) or before (-) the line identified by the address is referenced. A single - refers to the line before the current line. The + or - signs at the end of an address have a cumulative effect; the address ++ thus addresses the second line after the current line, 3++ addresses line 5, and ++ and .+2 are identical. % The % (percent) sign stands for the address pair 1,$, i.e. the entire buffer. 332 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, parameters Parameters The following parameters are used with ex commands: line = address A single line address, which you can specify in any of the forms described earlier in the Addressing section. line not specified: The default value (the period .) applies. The period stands for the current line. range = address,address range = address;address A pair of line addresses that defines an inclusive range of lines. The addresses can be separated by a comma or a semicolon. A range should not be specified together with a number n, since the last address of the specified range will then be interpreted as the first address of a range of n lines that begins with the last address. In other words, you would end up addressing a range that comes after the one intended. This has been taken into account in the ex command syntax. range not specified: The default value .,. applies. .,. represents only the current line. n A positive integer. In n you specify the number of lines to be processed. n not specified: The default value is 1. flag Ë The blanks need not always be specified. However, in the interest of clarity, they have not been indicated as optional here. Any number of plus or minus characters may be combined with these parameters. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 One or a combination of the ex commands # (see nu), p, and l. These commands display a line in a specific format and are executed after the preceding ex command completes. U22794-J-Z125-6-76 333 ex, commands Commands Overview of ex commands and their abbreviations 334 [CTRL]D (scroll) display n lines, where n=$scroll (see options) ab abbrev define abbreviations a append add text after specified line ar args display argument list of command line c change replace text line co copy copy text range d delete delete text range e edit change edited file f file display current file name g global execute command for all lines matching /RE/ i insert insert text lines j join join two lines l list output text with non-printing characters map --- define macros k mark mark lines m move move line range ma mark mark lines n next edit next file nu number number and output lines # number number and output lines pre preserve preserve contents of buffer p print print range of text pu put put lines back in buffer q quit quit the editor r read read copy of a file into the buffer rec recover reconstruct file after system crash rew rewind rewind argument list (cf. ar) se set display and set options sh shell call shell so source read command from file s substitute search and replace unab unabbrev cancel word from abbreviation list made with do U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, commands u undo undo effect of previous command unm unmap remove macro definition made with map v --- like g, but for all lines that do not match /RE/ ve version output version number of the editor vi visual switch to vi w write write buffer contents to file x exit quit editor after saving buffer content ya yank copy lines to buffer z (window) output specific text range ! (escape) execute shell command &s (resubst) repeat the last substitute command < (lshift) shift text range to left > (rshift) shift text range to right = (line no) display the line number No command specified If you specify only a line or a range, the command p (print) is automatically assumed and executed. If a null line is entered, the next line is printed (equivalent to .+1p) [CTRL]D (ASCII EOT) prints the next n lines, where n is the value of the ex option scroll. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 ab[brev]ËwordËtext (abbreviate) This command is only effective in vi mode! If you enter word in the vi input mode as a complete word (i.e. not as a word fragment), it is replaced by the string text. If text is to include special characters, e.g.Ú, these characters must be preceded by [CTRL]V. [line]Ëa[ppend][!] (append) Causes ex to enter input mode, placing the input text after the specified line. Use a line value of 0 to put a line at the beginning of the buffer. The last line of new input becomes the new current line. If there is no new input, the target line becomes the current line. Input is terminated by a period (.) entered in column 1. ar[gs] (arguments) Prints the argument list from the command line of the ex call, enclosed in square brackets [...]. U22794-J-Z125-6-76 335 ex, commands lineËc[hange][!]Ën rangeËc (change) ex switches to input mode. n lines or the lines in range are replaced by the lines you enter next. The last input line becomes the current line. If no text lines are entered, the specified range is deleted, i.e. c has the same effect as the d (delete) command. Input is terminated by a period (.) entered in column 1. chd[ir][!]Ë[directory] cd[!]Ë[directory] (chd/cd - change directory) ex changes the current working directory to directory. directory not specified: The directory name in the HOME environment variable will become the new working directory. [range]Ëco[py]Ëline[Ëflags] [range]ËtËline[Ëflag] (copy) Copies the lines specified by range to after line. If line is assigned a value of 0, the range of lines (i.e. text) will be copied to the beginning of the buffer. [line]Ëd[elete][Ëbuffer][Ën] [range]Ëd[elete][Ëbuffer] (delete) The lines in range, or n lines from the given line, are deleted from the buffer. If a named buffer is specified, the deleted text is saved in it. You can use the ex command pu to retrieve the contents of this buffer if you wish. The first line following the deleted material becomes the current line, unless the deleted lines were at the end of the buffer. In that case, the last line in the buffer becomes the current line. e[dit][!][Ë+line][Ëfile] ex[!][Ë+line][Ëfile] (edit) The named file is edited. If the current buffer has been modified since the last w (write) command, ex warns you and aborts the command. You can, however, force the execution of the e command by appending an exclamation mark to the e: e! file. The current line is the last line of the buffer; however, if this command is called from vi, the current line becomes the first line of the buffer. +line The specified line becomes the current line. line can be given as: – a line number n – the dollar symbol $ (for end of file) – a regular expression in the form /RE or ?RE. 336 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, commands f[ile][Ëname] (file) Prints the current file name and other information, e.g. the number of lines and the position of the current line. name specified: name becomes the current file name rangeËg[lobal]/RE/cmds (global) First marks all lines within the given range that match the pattern specified in RE; then applies the given cmds to the each of marked lines in turn, with each marked line becoming the current line while it is being edited. The commands given in cmds may be specified on separate lines, provided newline characters are escaped with a backslash. If cmds are omitted, all lines will be printed. The a(ppend), c(hange), and i(nsert) commands are allowed; the terminating period at the end of cmds may be omitted. The visual command is also permitted, and takes input from the display terminal. The following commands are not permitted in cmds: global and undo. The following edit options are not allowed in cmds: autoprint, autoindent and report. Example 1,$g/^\*/s//+/ All occurrences of * in the first column ^ of line 1 and of all lines through to the end of the file ($) are replaced by a plus character (+) by the substitute command (s). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 [line]Ëi[nsert][!] (insert) ex enters input mode; the input text is placed before the specified line. The last line inserted becomes the current line, but if no text is inserted, the line before the target line becomes the current line. Input is terminated by a period (.) entered in column 1. [line]Ëj[oin][!][Ën][Ëflag] [range]Ëj[oin][!][Ëflag] (join) Joins the lines in range, or n lines from line, into one line. The command inserts at least one blank between two previously split lines; two blanks are provided if a line ends with a period. If a following line begins with a right parenthesis, no blanks are inserted. Extra white space at the start of a line is discarded. Appending an exclamation mark to the j command (j!) produces a simpler join with no white space processing. [line]Ël[ist][Ën][Ëflag] [range]Ël[ist][Ëflag] (list) Displays the specified lines. Tab characters are replaced by ^I, and the end of each line is marked with a trailing $. The only useful flag is #, when the lines are to be preceded by their line numbers. The last line printed becomes the current line. U22794-J-Z125-6-76 337 ex, commands map[ËxËcommands] map![ËxËtext] Format 1 Format 2 Only works with vi! Format 1: Macro definitions for vi command mode This format of the map command is used to define macros for use in the vi command mode. The first argument x is a single character, or the sequence #n, where n is a digit that refers to function key n. When this character or function key is typed in vi command mode, vi responds as if the corresponding commands were entered. The specified commands are interpreted as a sequence of vi commands. If special characters, white space, or newline characters are to be used in the commands, they must be escaped with [CTRL]V. Example 1 You want to define a macro which replaces an * occurring at the beginning of a line (column 1) by a blank Ë throughout the entire file. The name of this macro is to be *. Enter the following in your .exrc file (see section Presetting ex) so that you can call the macro when required: :map * :1,$s/^\*/ / Example 2 You now want to define a macro and bind it to function key [F1]. This macro is to search for the next line that begins with a particular regular expression RE and then automatically delete this line. To do this, you enter (from vi command mode): :map [CTRL]V [F1] /^rA [CTRL] V Údd Ú Format 2: Macro definitions for vi input mode This format of the map command defines macros for use in vi input mode (see Format 1 above). Every x entered in vi input mode is replaced by text. (In the ab command, by contrast, x is replaced only when alone). If x is not to be replaced by text, it must be escaped by preceding it with [CTRL]V. Formats 1 and 2: Macro definitions can be cancelled with: unmap x or unmap! x [line]Ëma[rk]Ëx [line]ËkËx (mark) Marks the specified line with the character x, which must be a single lowercase letter. The x must be preceded by a blank or tab. The current line position is not affected. 338 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, commands [range]Ëm[ove]Ëline (move) Moves the specified lines (range) to after the target line. The first of the moved lines becomes the current line. n[ext][!][Ëfile]... file not specified: (next) The next file from the command line argument list is edited (cf. f and ar). If the current buffer has been modified since the last w (write) command, ex warns you and aborts the command. You can, however, force the execution of the n command by entering an exclamation mark after the n: n!. file specified: The previous argument list is replaced by the specified file(s), and the first specified file is edited. [line]Ënu[mber][Ën][Ëflag] [range]Ënu[mber][Ëflag] [line]Ë#[Ën][Ëflag] [range]Ë#[Ëflag] (number) Prints the lines, each preceded by its line number. The only useful flag in this case is l. The last line printed becomes the current line. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 pre[serve] (preserve) The current editor buffer is saved as though the system had just crashed. The pre command is for use in emergencies, e.g. when a w (write) does not work because the disk is full, and the buffer contents cannot be saved in any other way. [line]Ëp[rint][Ën] [range]Ëp[rint] (print) Prints the specified lines, with non-printing characters printed as control characters in the form ^x; DEL is represented as ^?. The last line printed becomes the current line. [line]Ëpu[t][Ëbuffer] (put) Lines deleted with d (delete) or copied to a buffer with y (yank) are put back in after the specified line. buffer represents a buffer name from a to z. buffer not specified: The text in the unnamed buffer is retrieved. q[uit][!] (quit) Quits the editor. If the buffer has been modified since the last w (write) command, a warning is printed and the q command fails. You can, however, force the execution of the q command by appending an exclamation mark to the q: q!. All changes not saved with w will then be discarded. U22794-J-Z125-6-76 339 ex, commands [line]Ër[ead][!][Ëfile] (read) Places a copy of the specified file in the buffer after the target line. Use a value of 0 to place text at the beginning of the buffer. If there is no current file at this point (e.g. when ex is called without a file name), then file becomes the current file. The last line read becomes the current line; in vi mode, the first line read becomes the current line. file not specified: The current file is read. If file is given as !cmd, then cmd is interpreted as a POSIX command and passed to the shell. The output of the command is then read in to the buffer. rec[over]Ëfile Recovers file from the save area after an editor or system crash. rew[ind][!] (rewind) The argument list (see ar) is rewound, and the first file in the list is edited. If the buffer has been modified since the last w (write) command, a warning is printed and the rew command is not executed. You can, however, force the execution of the rew command by appending an exclamation mark to the rew command: rew!. All changes not saved with w are then discarded. se[t][Ëparameter] (set) The set command can be used to display or set options. There are two types of options: those that have "Boolean" (i.e. on or off) values and those that do not. One example of a Boolean parameter is the number option. If this option is set, line numbers are displayed; when nonumber is set, no line numbers are displayed. By contrast, the report option is non-Boolean. The value of this option (default = 5) defines the number of lines that must be changed by a command before ex and vi issue a message. parameter all The values of all options are displayed. option? The current value of the specified option is displayed. option Only for options with Boolean values: The option is set. nooption Only for options with Boolean values: The option is not set. option=value Only for options with non-Boolean values: The option is assigned the specified value. parameter not specified: set displays user-defined ex options, i.e. options that deviate from default settings. More detailed information on ex options is provided in the corresponding section. 340 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, commands sh[ell] If the SHELL variable is set, the shell defined in that variable is invoked; otherwise, the Bourne shell sh. When you exit the shell, you will be returned to the editing session at the point you left off. so[urce]Ëfile Reads and executes commands from the specified file. Such so commands may be nested. [line]Ës[ubstitute][/RE/repl/[options][Ën][Ëflags]] [range]Ës[ubstitute][/RE/repl/[options][Ëflags]] (substitute) The first occurrence of a pattern that matches RE (regular expression) in each line of the given range is replaced by the string repl (see “Regular expressions” on page 328 and “Replacement strings” on page 329). The range is either given in range or specified as n lines from the specified line. /RE/repl not specified: The /RE/repl from the previous substitute command will be used. options g (global) All strings that match RE in the line are substituted. c (confirm) Before each substitution, the line is output with the pattern to be replaced shown in the line below it, marked by a ^ character. Entering y causes the substitution to be made; any other input causes the command to abort. The last line that contains a substitution becomes the current line. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 una[bbrev]Ëword (unabbreviate) word is deleted from the list of abbreviations set up by ab. u[ndo] (undo) Reverses the changes made by the previous editing command. g (global) and vi (visual) are considered single commands in this case. Commands which affect the external environment, such as w (write), e (edit), and n (next), cannot be undone. An undo can itself be reversed with a follow-up u. All markers for lines changed and subsequently restored are lost with u. unm[ap][!]Ëx (unmap) Removes the macro definition created by map for x. [range]Ëv[ice]/RE/cmds (vice versa) This is the same as the global command, except that cmds are applied to all lines that do not match the pattern RE. ve[rsion] Prints the current version of the editor. U22794-J-Z125-6-76 341 ex, commands [line]Ëvi[sual][Ëtype][Ën] Enters vi mode at the specified line. The type is optional and may be given as a minus sign (-) or a period (.), as in the z command, to specify the position of the specified line on the screen window. The default is to place the line at the top of the screen window. n specifies an initial window size; the default is the value of the ex option window. The command Q exits vi mode and returns you to ex. For further information, see section “vi screen oriented (visual) display editor” on page 803. [rangeË]w[rite][!][Ëfile] [rangeË]wq[!][Ëfile] Format 1 Format 2 Format 1: Write to a file (write) The specified range is written to the named file, and the number of lines and characters written is printed. If an alternate file is specified, and the file exists, the command will fail in order to prevent the alternate file from being accidentally overwritten. The execution of w can, however, be forced by appending an exclamation mark to the command: w!. To append to the file, use the form w>>. If the file does not exist, an error message is issued. If !cmd is specified instead of file, then cmd is interpreted as a POSIX command. The command interpreter is invoked, and the specified range is passed as standard input to the command. range not specified: The entire current file is written to file. file not specified: The current file is used by default. The w command cannot be executed if there is no current file and no file is specified. Format 2: Write to a file and quit ex (write and quit) The command wq is equivalent to a w followed by a q; wq! is equivalent to w! followed by q. x[it][!] (exit) Writes out the buffer if changes have been made since the last w and then (in any case) quits. lineËya[nk][Ëbuffer][Ën] rangeËya[nk][Ëbuffer] Copies (yanks) the specified range, or n lines from the specified line, to the named buffer. buffer not specified: If no buffer is specified, the unnamed buffer is used. 342 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, commands [line]Ëz[Ëtype[]Ën] (window) Displays n lines from the area in which line is located. n not specified: n defaults to the value of the window variable. type type is an optional parameter and can be specified as follows: - A - causes the line to be placed at the bottom of the screen. + A + causes the line to be placed at the top of the screen. . A . causes the line to be placed at the bottom of the screen. ^ A ^ writes out n lines starting n*2 lines before the addressed line. The net effect of this will be that a z^ command following another z command writes the previous page. = A =centres the addressed line on the screen with a line of hyphens written immediately before and after it. The number of preceding and following lines of text written will be reduced to account for these lines of hyphens. The last line printed becomes the current line. type not specified: line is placed at the top of the displayed area. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Caution: ex prints the number of logical rather than physical lines. More than a screen full of output may result if there are lines which are longer than the screen width. !Ëcommand (escape) The remainder of the line after the exclamation mark is passed to the system command interpreter for execution. A warning is issued if the buffer has been changed since the last w (write) command. The specified command is then executed. If the command output has not been redirected, it is displayed on the screen, but does not change the file. The command itself may, however, modify the file, e.g. !cat /etc/profile>> %. A single ! is printed when the command completes. The current line position is not affected. Within the text of command, the percent sign % and the hash character # are expanded as file names (see “Current and alternate file” on page 327). An exclamation mark in command is replaced with the text of the previous ! command. Thus, !! means "repeat the preceding command". If any such expansion is done, the expanded line will be echoed. U22794-J-Z125-6-76 343 ex, commands [range]Ë!Ëcommand (escape) In this form of the ! command, the lines specified in range are passed to the command as standard input and replaced by the output of the command. range not specified: range is not replaced by the current line (.,.); the other form of the ! command applies. " Command lines that start with double quotes " are ignored. This means that you can use lines of this kind to insert comment lines in a command script. lineË&optionsËnËflags range&optionsËflags lineËs[ubstitute]optionsËnËflags ranges[ubstitute]optionsËflags (resubst) Repeats the previous s (substitute) command, as if & were replaced by the previous s/RE/repl/. The same effect is obtained by omitting the /RE/repl/ string in an s command. lineË<Ën rangeË< (lshift) Shifts the defined line range (or the n lines that follow line) to the left by the number of spaces specified by the shiftwidth option. White space (blanks and tabs) is lost in the shift process; other characters are not affected. The last line changed becomes the current line. lineË>Ën rangeË> (rshift) Shifts the defined line range (or the n lines that follow line) to the right by the number of spaces specified by the shiftwidth option. White space (blanks and tabs) is not lost, but inserted as required. line= (line number) Prints the line number of the specified line. The current line position is not affected. line not specified: The line number of the last line is displayed. 344 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, options ex options ex provides a number of options with which you can govern the behavior of both the ex and (more importantly) the vi editors (see “Customizing the vi environment” on page 839). All options have default settings; these settings are valid at the time ex or vi is invoked. Use the ex command se (set) if you wish to have all options displayed: set allÚ The above command can also be used to change one or more options: set showmode scroll=15Ú This command shows the vi input mode in the status line and sets the number of lines scrolled by the [CTRL]D key to 15. The command: setÚ displays all options set to non-default values. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 There are two types of options: those that have "Boolean" (i.e. on or off) values and those that do not. One example of a Boolean parameter is the showmode option. When this option is not set, it is named noshowmode. The scroll option, by contrast, is an example of a nonBoolean parameter. autoindent, ai noautoindent, noai (default) If autoindent is set, each line in insert mode is aligned with the beginning of the previous line; tabs and blanks are inserted to produce this alignment. The starting indentation of a line is determined by the line it is appended after (a), the line it is inserted before (i), or the first line to be changed (c). Extra indentation can be provided as usual; succeeding lines will automatically be indented to the new alignment. To reduce the level of indentation, you can press [CTRL]D one or more times to move the start of the line to the left to positions which are multiples of shiftwidth. Thus if the current cursor position is 25 and shiftwidth is set to 10, pressing [CTRL]D once will move the cursor to the left to position 20, while pressing it twice will take the cursor to position 10. A caret ^ followed by a [CTRL] D removes all indentation temporarily for the current line; a 0 (zero) followed by a [CTRL] D removes all indentation. autoprint, ap noautoprint, noap (default) Prints the current line after each command that changes buffer text. autoprint is suppressed during global search and replace operations (see g, s and v). U22794-J-Z125-6-76 345 ex, options autowrite, aw noautowrite, noaw (default) Writes the buffer to the current file if the buffer has been modified, and an e (edit), n (next), rew (rewind) or ! (escape) command has been given. beautify, bf nobeautify, nobf (default) Causes all control characters other than tab, newline and form feed to be discarded from the input text. directory=dir dir=dir The value of dir specifies the directory which is to hold the editor buffer. If the user does not have write permission for this directory, the editor quits. edcompatible, ed noedcompatible, noed Causes the presence of g and c suffixes on s (substitute) commands to be remembered for use as toggles. errorbells, eb noerrorbells, noeb Rings the terminal bell before displaying error messages in the last line (usually in reverse video). exrc, ex This option has been deactivated for security reasons. It normally causes .exrc files in the current directory to be evaluated. flash, fl (default) noflash, nofl If the terminfo description contains an entry for flashing the screen to indicate an error, this option can be used to inform users when they have made an invalid entry. hardtabs=number ht=number If the terminal has hardware tabs, this option can be used to set the number of spaces to which the tab stops are set (to optimize screen output). ignorecase, ic noignorecase, noic (default) Treats all uppercase characters in the text as lowercase when a search is made. Uppercase characters in regular expressions are also mapped to lowercase, except in character class expressions. 346 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, options lisp nolisp (default) Activates the autoindent option and modifies the vi commands left parenthesis (, right parenthesis ), left brace {, right brace }, double left brackets [[, and double right brackets ]] suitably. list nolist (default) All printed lines will be displayed with tabs shown as ^I, and the end of line marked by a $. magic (default) nomagic Changes interpretation of characters in regular expressions and substitution replacement strings (see the relevant sections). mesg (default) nomesg Grants/denies other users permission to write to the terminal (e.g. with the write command). modelines (default) nomodelines The first and last five lines of a file that is read in are interpreted as editor commands and executed if they are in the form: ex:command: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 novice nonovice (default) Defines the level of detail for error messages. number, nu nonumber, nonu (default) Causes lines to be printed with line numbers. optimize, opt nooptimize, noopt (default) Allows you to set the terminal with or without automatic carriage returns (to optimize output). paragraphs=string para=string The value of this option is a string in which each successive pair of characters specifies the name of an nroff macro that begins a paragraph. A macro appears in the text in the form .XX, where the . is the first character in the line. U22794-J-Z125-6-76 347 ex, options prompt (default) noprompt When prompt is set, the : prompt is displayed in command mode; otherwise, there is no command-mode prompt. readonly noreadonly (default) If readonly is set, the editor can only be used to read files, not to make changes to the text. If noreadonly is set, you can make changes to files. redraw (default) noredraw The editor simulates an intelligent terminal on a dumb terminal. Since this is likely to require a large amount of output to the terminal, it is useful only at high transmission speeds. remap (default) noremap If remap is set, macro translation allows for macros defined in terms of other macros; translation continues until the final product is obtained. Only one step of translation is performed if noremap is set. report=n When the number of lines changed, deleted, or copied by the last command exceeds n, a message is issued in the status line. scroll=n The value n specified for scroll determines the number of lines that the screen will scroll when a [CTRL] D command is entered. It also controls the number of lines displayed by a z command (twice the value of scroll). sections=string sect=string The value assigned to this option is a string in which each successive pair of characters specifies the name of an nroff macro which begins a section. A macro appears in the text in the form .XX, where the . is the first character in the line. shiftwidth=n sw=n The value n specified for sw is used for the spacing of tab stops used by the tab key, the autoindent option, and by the < and > (shift) commands. showmatch, sm noshowmatch, nosm (default) When a right parenthesis ) or right brace } is entered in vi, the matching left parenthesis ( or left brace { is shown, provided the matching character is still on the screen. 348 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex, options showmode, smd noshowmode, nosmd (default) When smd is set, an indication is provided in the status line as to whether vi is in vi input mode. slowopen, slow noslowopen, noslow (default) In vi, prevents screen updates during input to improve throughput on unintelligent terminals. tabstop=n ts=n n specifies the software tab spacing to be used by the editor when expanding tabs in the input file. taglength=number tl=number Defines how many characters are to be considered significant in searches with the :tag command. A value of 0 means that all characters are to be considered. tags=files Names of tag files, separated by blanks. term=string string tells vi what type of terminal is being used. (The default is the value of the environment variable TERM.) Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 terse noterse (default) Setting terse causes shorter error messages to be issued. timeout notimeout Sets/cancels a timeout period. ttytype=string string tells vi what type of terminal is being used. (The default is the value of the environment variable TERM.) warn (default) nowarn When warn is set, the warning No write since last change is issued if a :! command is given before the most recent changes to the editor buffer have been saved with w. window=n The number of lines in a vi text window. U22794-J-Z125-6-76 349 ex wrapmargin=n wm=n Only effective in vi. If n>0, a newline is automatically added to an input line at a word boundary such that lines end at least n spaces from the right margin of the terminal screen. The setting of automatic line breaks can be deactivated by setting the value of n to 0 (default). wrapscan, ws (default) nowrapscan, nows Setting wrapscan causes searches begun by the /.../ or ?...? commands to wrap around from the end of a buffer to the beginning (or vice-versa). When nows is set, the search runs through to the end or beginning of the buffer as appropriate and then terminates. writeany, wa nowriteany, nowa (default) When nowa is set, a check is performed before a w command to determine whether the file exists. This is to prevent an existing file from being accidentally overwritten. You can override the overwrite protection with w!. Setting wa inhibits the normally provided overwrite protection. Error When an error occurs, ex sends the acoustic signal BEL (see section “ASCII character set (ISO 646)” on page 889) to the terminal and prints a message. If an interrupt signal is received, ex returns to command level, allowing you to enter a new ex command. If the editor input is from a file, ex exits at the interrupt signal. If ex detects an internal error, it attempts to preserve the buffer if the most recent changes have not been saved. If you wish to access the backed up data, you must call ex with the -r option. File $HOME/.exrc File containing default values for ex and vi. These defaults are overridden if conflicting settings have been assigned to EXINIT. Variable TERM The type of data terminal used must be defined in the environment variable TERM. EXINIT Environment variable with default values for ex and vi. These defaults always apply. PATH Determine the search path for the shell command specified in the editor commands shell, read and write. 350 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc ex HOME Determine a pathname of a directory that will be searched for an editor startup file named .exrc. 7. Juli 2009 Stand 11:58.29 SHELL Determine the preferred command-line interpreter for use in !, shell, read and other commands with an operand of the form !string. For the shell command, the program will be invoked with the single argument -i, for all others it will be invoked with the two arguments -c and string. If no SHELL variable is set, or it is set to a null string, the sh utility will be used. COLUMNS Override the system-selected horizontal screen size. LINES Override the system-selected vertical screen size, used as the number of lines in a screenful and the vertical size in visual mode. Locale The following environment variables affect the execution of ex: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the behavior of character classes within regular expressions, the classification as upper- or lower-case letters, the case conversion of letters, and the detection of word boundaries. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH U22794-J-Z125-6-76 Determine the location of message catalogs for the processing of LC_MESSAGES. 351 ex Example The following example demonstrates and explains a number of ex commands: $ ex figures - Call ex (file name "figures") "figures" 4 lines, 19 characters :set number - Output line numbers :1,$p - Output line 1 through to last line 1 one - Original contents of figures 2 two 3 three 4 four :1 c 1 - Modify line 1 1 ONE - New line 1 2 . - Quit input mode :2,3 co 4 - Copy lines 2 to 3 after line 4 6 three :1,$ g/two/s//TWO/ - Replace "two" by "TWO" throughout the file :2 a - Insert new line after line 2 3 THREE - New line 3 4 . - Quit input mode :4 i - Insert new line before line 4 4 FOUR - New line 4 5 . - Quit input mode :5,$ d a - Delete line 5 and all lines to end of file 4 FOUR :1,$p - Output line 1 through to last line 1 ONE 2 TWO 3 THREE 4 FOUR :wq - Save the contents of the buffer and quit ex "figures" 4 lines, 19 characters See also 352 ed, vi U22794-J-Z125-6-76 exec exec execute commands and open, close or copy file descriptors The POSIX shell built-in exec performs two functions: ● 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command It overlays the current shell with another program (Format 1). When this program starts, the current shell is terminated. No new process is created, as is evident from the fact that the process ID does not change (see Example 2 on page 356). If you enter exec interactively, when the specified program exits you return to the parent shell of the previous shell; if your previous shell was a login shell, your session terminates. If exec is called from a shell script, the script terminates. Commands that follow an exec call in the script will never be executed. ● Syntax It can be used to redirect the standard input or the standard output of the shell to a file (Format 2). All commands entered after exec has been executed will read from or write to this file until you terminate the current shell. Format 1: execËprogram[Ëredirection] Format 2: execËredirection Format 1 Replacing the shell with another program execËprogram[Ëredirection] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 program Any command, program or shell script, but not another sh command. You will need execute permission for the associated file. The current shell terminates, and program is executed instead. On completion of the specified program, control reverts to the old shell’s parent, or the welcome screen is displayed. redirection If the specified program reads from standard input or writes to standard output, a file can be assigned for the input or output instead. redirection can be specified as follows: >file The standard output of the specified program is redirected to file. Any data previously in file will be deleted. >>file The standard output of the program specified is redirected to file. Data already contained in file is not deleted; program output is appended to it instead. U22794-J-Z125-6-76 353 exec Format 2 Built-in sh command 2>file The standard error output of the specified program is redirected to file. file All commands executed by the current shell write their output to the specified file sequentially. Data previously in file is deleted. The output from all commands can be collected in this way. If you have entered exec interactively, the redirection can only be cancelled by: – pressing the [END] or @@d. This terminates the current shell. – entering exec >/dev/tty. This redirects the standard output back to the screen. If exec is called from a shell script, the redirection will only apply to commands that follow the exec call in the script. Redirection can be cancelled within the script by including the command exec >/dev/tty at the appropriate position in the script. This will redirect the standard output of all subsequent commands back to the screen. 354 >>file All commands executed by the current shell write their output to the specified file sequentially. Data already contained in file is not deleted; program output is appended to it instead. 2>file Standard error is redirected to file for all commands executed by the current shell. U22794-J-Z125-6-76 exec 128: A command was interrupted by a signal. trap is executed for EXIT before the shell terminates. This fails to occur only if exit itself is called in this trap. In this latter case, the shell terminates immediately. You can use the command echo $? to query the exit status. n not specified: The exit value of the command executed before the exit call is used. Exit status 358 The exit status is n if it is set. Otherwise the exit status is the exit status of the last command executed or zero if no command has been executed. If exit is executed as part of a trap then the last command executed is taken to be the command which was executed immediately before the trap. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command exit Example 1 The false command can be implemented by means of the following shell script: : Shell version of the false command : Exit status allways 1 exit 1 Example 2 The two shell scripts named end and check will be used to demonstrate how the exit status can be evaluated: – The end script contains the following: : Invocation with sh end file if [ -f "$1" ] then exit 2 elif [ -d "$1" ] then exit 3 else exit 4 fi – The check file is scripted as follows: : Invocation sh end "$1" case $? in 2) echo 3) echo 4) echo esac with sh check file Contents of file $1:; cat $1;; Contents of $1:; ls -l $1•pg;; Entering $1 is meaningless for this script! The shell script check is now initiated: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ sh check .profile Contents of file .profile: HOME=/usr1/rose/src export HOME ... The shell script check calls the script named end. This script returns an exit status of 2, since .profile is a normal file. The commands specified in the case statement under the matching pattern 2 are then executed. The contents of the above two shell scripts cannot be simply combined into a single file, since the exit command terminates the script. U22794-J-Z125-6-76 359 exit Built-in sh command This shell script endaction shows how the exit status can be interpreted within a script: : Invocation with sh endaction file (if [ -f "$1" ] then exit 2 elif [ -d "$1" ] then exit 3 else exit 4 fi) case $? in 2) echo Contents the file $1:; cat $1;; 3) echo Content of $1:; ls -l $1•pg;; 4) echo Entering $1 is meaningless for this script! esac The parentheses around the if statement cause a subshell to be invoked. This subshell terminates with the exit status that is specified in the relevant exit command. Control is subsequently returned to the parent shell, i.e. the shell that processes the endaction script. This shell executes the remaining commands. See also 360 false exit() [4] U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc expand expand convert tabs to spaces The expand command writes files or the standard input to the standard output with tab characters replaced by one or more blanks needed to pad the line to the next tab stop. All backspace characters are copied to the output and cause the column position count for tab stop calculations to be decremented. The column position count will not be decremented below zero.. Syntax Format 1: expand[Ë-tËtablist][Ëfile...] Format 2: expand[Ë-tabstop |Ë-tab1,tab2,...,tabn][Ëfile...] Format 1 expand[Ë-tËtablist][Ëfile...] -tËtablist Specifies the tab stops. The argument tablist must consist of one or more numbers, separated by blanks or commas, in ascending order. A list separated by blanks must be enclosed in quotes. If only one number is specified, the tab stops will be set to tablist column positions instead of the default 8 column positions. If multiple numbers are given, the tabs will be set at the specified column positions. Each tab stop position N must be an integer value greater than zero, and the specifications must be in ascending order. This means that tabbing from the start of the line of output to position N causes the next character output to be in the ( N +1)th column position in that line. file The file whose tab characters are to be replaced by blanks. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 If the expand command has to process a tab character at a position beyond the last position specified in a multiple tab stop list, the tab character is replaced by a blank in the output. U22794-J-Z125-6-76 361 expand Format 2 expand[Ë-tabstop |Ë-tab1,tab2,...,tabn][Ëfile...] -tabstop |Ë-tab1,tab2,...,tabn Specifies the tab stops. A single number is specifed as tabstop with a leading minus; multiple tabstops are specified after a leading minus as tab1, tab2, ..., tabn and so forth. file The file whose tab characters are to be replaced by blanks. Standard Output (stdout) The standard output is equivalent to the input files with tab characters converted into the appropriate number of blanks. Locale The following environment variables affect the execution of expand: LANG Specifies a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If one of the internationalization variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If this variable has been assigned a value, i.e. it is not a null string, this value overrides the values of all the other internationalization variables. LC_CTYPE Determines the internationalized environment for the interpretation of bytesequences (e.g. single-byte characters as opposed to multi-byte characters in arguments and input files). The internationalized environment for the processing of tab characters and blanks and for the specification of the width in column positions each character would occupy on a constantwidth output device. LC_MESSAGES Determines the format and contents of error messages. NLSPATH See also 362 Determines the position of message catalogs for the processing of LC_MESSAGES. tabs, unexpand U22794-J-Z125-6-76 export export set export attribute for variables The POSIX shell built-in export marks the specified shell variable for export. This means that the name of this variable and its value will subsequently be known and accessible to all commands. Exported variables are deleted when the shell in which they were defined and exported is terminated. Frequently used variables should therefore be defined and exported in the $HOME/.profile file. Positional parameters and shell functions cannot be exported. Some standard variables of the shell are available in all subshells without needing to be exported. These include HOME, IFS, PATH, PS1 and PS2. If you wish to assign some other value to these variables, and if the modified value is to be valid in every subshell, you will need to export these variables. Otherwise, the default value is valid in each subshell. The built-in sh command set outputs all variables and associated values which are defined in the current shell. This therefore includes variables which you have not exported. The command export outputs the names and values of all shell variables which are passed to each called command and each subshell. 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command Syntax Format 1: export[Ëname[=value]]... Format 2: exportË-p Format 1 export[Ëname[=value]]... name not specified: export writes the names of all exported shell variables in the current shell to the standard output. The output takes the following form: name=value ... Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 name[=value] Name of the shell variable which you wish to export. You may also assign a value value to this variable after calling export. You may specify as many shell variables as you wish, each separaed by a space. U22794-J-Z125-6-76 363 export Format 2 Built-in sh command exportË-p -p If -p is set, export outputs the names and values of all the variables which have been exported. The output has the following format and is sent to the standard output: “export %s=%s\n”, name, value The option -p provides transferrable access to the values which can be saved and then subsequently restored (e.g. by means of a dot procedure). The shell formats the output and ensures that the quotation marks are used correctly. This means that output is suitable for re-entry in the shell in the case of commands which have the same export results. Locale The following environment variables affect the execution of export: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH 364 Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 Example export The shell script ps1 is to display the value of the PS1 variable. The script file contains the following: : Invocation with sh ps1 echo PS1: $PS1 The following interactive session demonstrates why the shell variable PS1 has to be exported: $ export export HOME export PATH $ PS1=hello $ sh ps1 PS1: $ export PS1 $ export export HOME export PATH export PS1 $ sh ps1 PS1: hello 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command When you define a shell variable, it is only known in the current shell. Since a shell script is always run by a subshell, variables for shell scripts have to be exported. env, set Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 365 expr expr Built-in sh command evaluate arguments as an expression expr interprets command-line arguments as expressions and evaluates them in succession. The result of the evaluation is displayed on standard output. You can use expr to compare strings with one another, for example, or to perform calculations with integers. Syntax exprËexpressionË... expression expression may either consist of one operand only, or two operands linked by an operator. Any arbitrary string can be specified as an operand. Strings that consist of digits only (0 to 9) are interpreted as integers. Integers preceded by a minus sign are interpreted as negative numbers. Operands and operators are separated from one another by a separator. The value specified for the IFS variable is used as the separator. If you wish to enter a string which contains spaces or tabs as an operand you must therefore enclose the entire string in apostrophes ’...’ or quotes "..." to prevent these characters being interpreted as separators. You must also enclose special shell characters in apostrophes ’...’ or quotes "..." or quote them by means of the backslash \ (see IFS in the section “POSIX shell variables and parameter substitution” on page 52). If expression consists of only one operand, the result of the evaluation will be the operand itself. The following section describes how two operands can be linked. The operators are arranged in the order of increasing precedence; operators with equal precedence are enclosed in braces {...}. A result of 0 stands for the value 0, not a null string. Linking operators op1Ë|Ëop2 If op1 is neither the null string nor 0, the expression evaluates to op1; otherwise, op2. op1Ë&Ëop2 If neither op1 nor op2 is equal to the null string or 0, the result returned is op1; otherwise, 0. 366 U22794-J-Z125-6-76 expr op1ËrelËop2 rel may be one of the following relational operators: 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command < less than <= less than or equal to = equal to >= greater than or equal to > greater than != not equal to If the condition is fulfilled, the comparison returns a result of 1. If the condition is not satisfied, the result of the comparison is 0. If both op1 and op2 are integers, the comparison is numeric; otherwise, they are interpreted as strings and compared alphanumerically. op1Ë{+ -}Ëop2 If op1 and op2 are both integers, the result returned is the sum of, or difference between, the two numbers. If either of the arguments is not an integer, expr issues an error message (see page 368). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 op1Ë{* / %}Ëop2 When op1 and op2 are integers, the result is equal to the value obtained from the specified arithmetic operation: * Multiplication / Division (integers only) % Remaindering If either of the arguments is not an integer, expr issues an error message (see page 368). op1Ë:Ëop2 The strings op1 and op2 are compared with one another, starting with the first character in each string and ending with the last character in op2. op2 may be specified in the form of a simple regular expression (see section “Regular POSIX shell expressions” on page 877). If op1 and op2 match each other (i.e. from the first character in both strings to the last character in op2), expr usually returns the number of matching characters. However, if you enter the pattern \(...\) for op2, the part of op1 that matches this pattern will be displayed (see Example 6 on page 369 and Example 7 on page 369). (...) The use of parentheses (...) enables you to influence the sequence of evaluation. Parenthesized expressions are evaluated first even if they contain operators with lower precedence. U22794-J-Z125-6-76 367 expr Built-in sh command Exit status 0 if the expression is neither invalid nor null nor 0 1 if the expression is null or 0 2 for invalid expressions or division by 0 Error expr: Non-numeric argument You are only allowed to specify integers as operands when using the arithmetic operators +, -, *, /, %. expr: Division by zero You have tried to divide by 0. expr: Syntax error You have made a syntax error when calling expr, e.g. you have not delimited operands and operators by blanks or tab. expr: RE error When using the relational operator : in an expression, you have not specified the second operand as a simple regular expression in the correct format. Locale The following environment variables affect the execution of expr: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. LC_COLLATE also governs the behavior of relational operators in string comparisons. Thus if the letters a and ä form part of an equivalence class, the expression expr $var:‘[[=a=]] returns a value of 1 if the value of the variable is a or ä. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH 368 Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.29 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoe.doc Built-in sh command expr Example 1 Simple calculation: $ expr 21 + 9 '*' 2 / 6 24 Example 2 A value of 1 is added to variable a in the following example. $ echo $a 3 $ a=`expr $a + 1` $ echo $a 4 Example 3 This example compares two environment variables: $ echo $op1 $op2 text1 text2 $ expr $op1 = $op2 0 If the value of a variable is itself an operator used by expr, the comparison will not work. This problem can be solved by combining the variable with a "safe" character: $ echo $op1 $op2 = = $ expr $op1 = $op2 expr: syntax error $ expr X$op1 = X$op2 1 Example 4 Displaying the number of characters in VAR: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ echo $VAR Hallo $ expr $VAR : '.*' 5 Example 5 Comparing two strings: $ expr boycott : boy 4 Example 6 The absolute path name of a file, e.g. /usr/latino/parnassum/infinitum is stored in variable a. To obtain the basic file name, i.e. infinitum, you enter: $ expr abc : [\^d-f] 1 Example 7 The absolute path name of a file, e.g. /usr/latino/parnassum/infinitum is stored in variable a. To obtain the basic file name, i.e. infinitum, you enter: $ expr $a : '.*/\(.*\)' infinitum U22794-J-Z125-6-76 369 expr Built-in sh command Example 8 If variable a contains either the absolute path name or the basename of a file, you can extract the file basename as follows: $ expr $a : '.*/\(.*\)' \| $a 370 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc Built-in sh command false false return false value The built-in POSIX shell sh command false returns an exit status which is not equal to zero. This enables you to generate the condition false in shell procedures. Similarly, you can use the command true to generate the condition true (exit status equal to 0). Syntax false Exit status Always non-zero Example The exit status of false: $ false $ echo $? 1 true Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 371 fc fc process command history list The commands issued from an interactive POSIX shell are stored in a history file which can be accessed using the built-in fc command. fc allows you to: – edit individual command lines from the history file before they are executed (Format 1) – list command lines on standard output (Format 2) – change commands before they re-execute, without editing the history file (Format 3) Syntax Format 1: fc[Ë-r][Ë-eËeditor][Ëfirst[Ëlast]] Format 2: fcË-l[Ë-nr][Ëfirst[Ëlast]] Format 3: fcË-s[Ëold=new][Ëfirst] Format 1 fc[Ë-r][Ë-eËeditor][Ëfirst[Ëlast]] -r The commands are made available in reverse order. -eËeditor editor is the name of the editor to be used. If the editor name is not supplied, the value of the variable FCEDIT is used. If FCEDIT is not set, the default editor /usr/bin/ed is invoked. first[Ëlast] The range of commands from first to last in the last HISTSIZE commands typed at the terminal is selected for editing and subsequent execution. The first and last arguments may be specified as numbers or as strings. [+]number A positive number representing a command number; command numbers can be displayed with the -l option. -number A negative decimal number representing the command that was executed by this many commands previously. For example, -1 is the immediately preceding command. string A string is used to select the most recently entered command that begins with this string. first and last specified All commands entered between first and last are selected for editing. If first is a more recent command than last, the commands are listed for editing in reverse order (as with option -r). last not specified The value for first is used. first and last not specified The last (most recent) command is edited. 372 U22794-J-Z125-6-76 Format 2 fcË-l[Ë-nr][Ëfirst[Ëlast]] -l The commands and command numbers are merely written to standard output and can neither be edited nor executed. -n Command numbers are suppressed when listed with -l. -r Commands are listed in reverse order. 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fc first[Ëlast] The range of commands from first to last in the last HISTSIZE commands typed at the terminal is selected for editing and subsequent execution. The first and last arguments may be specified as numbers or as strings. [+]number A positive number representing a command number; command numbers can be displayed with the -l option. -number A negative decimal number representing the command that was executed by this many commands previously. For example, -1 is the immediately preceding command. string A string is used to select the most recently entered command that begins with this string. first and last specified All commands entered between first and last are listed. If first is a more recent command than last, the commands are listed for editing in reverse order (as with option -r). last not specified The previous command is listed. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 first and last not specified The previous 16 commands are listed. Format 3 fcË-s[Ëold=new][Ëfirst] -s The commands are re-executed. No editor is invoked. old=new The command is modified before being executed. The command is re-executed after new has been substitued for old. first All commands since first are executed. See Format 2 for a detailed description. first not specified The previous command is used. U22794-J-Z125-6-76 373 fc Error sh: /bin/ed: not found The shell variable FCEDIT is not set to ed. Variable HISTFILE If this variable is set when the POSIX shell is invoked, its value is the path name of the file that will be used to store the command history (see the section “Command re-entry” on page 65). HISTSIZE If this variable is set when the POSIX shell is invoked, the shell will remember the commands you enter (command history). The number of previously entered commands that are accessible by this shell will be greater than or equal to the given number. The default is 128. FCEDIT The name of the standard editor for the built-in fc command. Locale The following environment variables affect the execution of fc: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Listing the previous 16 commands: $ ls -l $ fc -s ls=fc : is identical to $ fc -1 374 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fc Example 2 Re-executing the previous command: $ fc -s is identical to $ fc -s -- -1 U22794-J-Z125-6-76 375 fg fg Built-in sh command run jobs in the foreground You can use the built-in POSIX shell sh command fg to run jobs in the foreground. You should only use this command if you used rlogin to access the POSIX shell. i Syntax fg[Ëjob-id...] job-id Each of the entered jobs is moved to the foreground. The section Jobs in the chapter "Entering commands from the POSIX shell" contains a description of the format of job-id. job-id not specified: The current job is moved to the foreground. Exit status 0 if execution is successful >0 if an error occurs Locale The following environment variables affect the execution of fg: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. Job %1 is to be moved to the foreground: $ fg %1 See also 376 bg, jobs, kill, wait U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fgrep fgrep search a file for a fixed-string pattern fgrep reads lines from one or more files or from standard input and searches the lines for strings. Unless told otherwise (by options), fgrep copies every line containing one of the specified strings to standard output. If you specify more than one input file, the relevant file name will be displayed before each output line. Syntax Format 1: fgrep[Ë-bchilnrvxy]Ë-eËpatternlist[Ëfile...] Format 2: fgrep[Ë-bchilnrvxy]Ë-fËpatternfile[Ëfile...] Format 3: fgrep[Ë-bchilnrvxy]Ëpatternlist[Ëfile...] The formats are described together since the strings which fgrep uses to compare the input lines are specified either via patternlist or using the option -e patternlist or -f patternfile. You must specify one of these arguments. Two of them or all three together are not permitted. No option specified fgrep outputs all lines that match at least one of the strings specified in list. If you specify more than one input file, each output line will be preceded by the name of the file in which the line was found. option -b (block) Each output line is preceded by the number of the block in which it was found. Each file is made up of 512-byte blocks which are numbered consecutively from 0. Option -b is sometimes useful in locating disk block numbers by context (see the offset argument for the od command on page 584, for example). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -c (count) fgrep outputs only the number of lines found (i.e. the lines that fgrep would have displayed without the -c option, see Example 4); the lines themselves are not displayed. -h (hidden) When searching multiple files, fgrep does not write the file name before each output line. -i or -y (ignore) fgrep does not distinguish between uppercase and lowercase. -l (list) fgrep simply outputs the names of files that contain at least one of the matching lines. (These are the lines that fgrep would output if the -l option were omitted, see Example 5 on page 381.) Each file name is printed just once. The lines themselves are not displayed. -n (number lines) Each output line is preceded by its line number in the relevant input file. Line numbering starts at 1. If fgrep is reading from standard input, the line number refers to the standard input. U22794-J-Z125-6-76 377 fgrep -r (recursive) Names that refer to directories are processed recursively; in other words, all the files and subdirectories in that directory are scanned as well. -v (vice versa) fgrep outputs all lines that do not match any of the specified strings. In conjunction with option -c: fgrep prints only the number of lines that do not match. In conjunction with option -l: fgrep only outputs the names of files containing such lines. -x (exact) fgrep outputs lines consisting solely of one of the specified strings. In conjunction with option -c: fgrep only outputs the number of such lines. In conjunction with option -l: fgrep outputs the names of files containing such lines. -eËpatternlist (expression) This option is needed if the first expression in patternlist begins with a - (dash). The -e option ensures that such strings are not interpreted as an option but as a list of strings to be matched with the input lines. -fËpatternfile (file) fgrep reads the search strings from the named patternfile. Each line in patternfile is interpreted as a string. patternlist List of strings that fgrep is to use when comparing input lines. The individual strings must be separated by newline characters. If patternlist includes newline characters or other characters that have a special meaning for the shell, you must enclose patternlist in single quotes: ’patternlist’. file Name of the file that fgrep is to scan. You may name any number of files. file not specified: fgrep reads input lines from the standard input. grep, fgrep and egrep The grep, fgrep and egrep commands perform similar functions and are largely identical in terms of usage. The following section lists the most important differences between these commands. grep processes simple regular expressions. Only one regular expression may be specified in each call. 378 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fgrep fgrep processes strings only. However, you may specify several strings in one call. The strings can either be entered directly in the command line, separated by newline characters, or passed to fgrep from within a file. fgrep is fast and compact and can search for a large number of strings. All specified strings are searched for in each individual line. 7. Juli 2009 Stand 11:58.30 egrep processes extended regular expressions. Among other things, these include all simple regular expressions with one exception: the \(...\) construct used in simple regular expressions does not have a special meaning in extended regular expression syntax and is hence not processed by egrep. Several regular expressions can be specified together, separated by newline characters. egrep interprets these newline characters as an OR operator (the vertical bar character; see section “Regular POSIX shell expressions” on page 877). The regular expressions can either be specified directly in the command line or passed to egrep via a file. Exit status Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale 0 Matching lines found 1 No matching lines found >1 Syntax error or “Cannot open file”. This exit status remains valid even if lines have been found in other input files. The following environment variables affect the execution of fgrep: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files) and the behavior of character classes within regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH U22794-J-Z125-6-76 Determine the location of message catalogs for the processing of LC_MESSAGES. 379 fgrep Example The files customer1 and customer2 are the basis for all the examples below. Their contents are as follows: customer1: 080685 120387 180588 999.98 1240.25 330.87 20 Units 3 Units 1 Units Item Item Item 038 023 332 Johnson Ltd. Skinner Ltd. Skinner Ltd. customer2: morrow lance, 86 sherwood street, london w1 skinner robert, 16 garden hill, london ec3 Example 1 Output lines that match a string (without an option and with option -i): $ fgrep Skinner customer1 customer2 customer1:120387 1240.25 3 Units customer1:180588 330.87 1 Units Item Item 023 332 Skinner Ltd. Skinner Ltd. If you also wish to display lines containing the word skinner in lowercase you enter: $ fgrep -i skinner customer1 customer1:120387 1240.25 customer1:180588 330.87 customer2:skinner robert, 16 customer2 3 Units Item 023 Skinner Ltd. 1 Units Item 332 Skinner Ltd. garden hill, london ec3 Example 2 Search several strings (without an option and with the -f option): $ fgrep 'Skinner > Johnson' customer1 customer2 customer1:080685 999.98 20 Units customer1:120387 1240.25 3 Units customer1:180588 330.87 1 Units Item Item Item 038 023 332 Johnson Ltd. Skinner Ltd. Skinner Ltd. Alternatively, you could write both strings into a file called names (each string in a separate line) and then call fgrep as follows: $ fgrep -f names customer1 customer2 Example 3 Output lines that do not contain the given string (option -v): $ fgrep -v Skinner customer1 customer2 customer1:080685 999.98 20 Units Item 038 Johnson Ltd. customer2:morrow lance, 86 sherwood street, london w customer2:skinner robert, 16 garden hill, london ec3 380 U22794-J-Z125-6-76 Example 4 Display the number of lines found (option -c): To begin with, the number of lines containing the string Skinner are to be output for each input file. $ fgrep -c Skinner customer1 customer2 customer1:2 customer2:0 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fgrep Next the number of lines that do not contain the string Skinner is to be displayed. $ fgrep -c -v Skinner customer1 customer2 customer1:1 customer2:2 Example 5 Display file names only (option -l): First the names of files containing the string Skinner are to be output. $ fgrep -l Skinner customer1 customer2 customer1 Now the names of files with lines not containing the string Skinner are to be displayed. $ fgrep -l -v Skinner customer1 customer2 customer1 customer2 Example 6 Display found lines with their line numbers (option -n): See also ed, egrep, grep, sed Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ fgrep -n -i skinner customer1 customer2 customer1:2:120387 1240.25 3 Units Item 023 Skinner Ltd. customer1:3:180588 330.87 1 Units Item 332 Skinner Ltd. customer2:2:skinner robert, 16 garden hill, london ec3 U22794-J-Z125-6-76 381 file file determine file type The file command takes a list of one or more files and classifies each file on the basis of its contents. The types distinguished by file include directories, special files, FIFO files, archive libraries, C source programs, executable programs, shell scripts, and normal text files. ! Syntax Caution! file looks up the magic number in the magic file to identify the target file. If it fails to identify the file by this method, it tries various plausibility checks. Consequently the results are not always reliable. Format 1: file[Ë-h][Ë-mËmagicfile][Ë-fËffile]ËargfileË... Format 2: file[Ë-h][Ë-mËmagicfile]Ë-fËffile[ËargfileË...] Format 3: fileË-c[Ë-mËmagicfile] Classify a file Format 1 file[Ë-h][Ë-mËmagicfile][Ë-fËffile]ËargfileË... Format 2 file[Ë-h][Ë-mËmagicfile]Ë-fËffile[ËargfileË...] -h (hidden) If argfile is a symbolic link, the link will not be followed and the following error message will be printed: file1: symbolic link to file2 -mËmagicfile (magic) Causes file to use magicfile instead of the system file /etc/magic to identify the magic numbers of the files being classified. -fËffile file interprets the ffile argument as the name of a file which contains the names of all files to be examined. If this option is omitted, you must name at least one file to be classified. argfile Name of the file to be classified by the file command. If argfile is a symbolic link, file will follow the link and test the original file referenced by the symbolic link. You can name any number of files. If the -f option is omitted, you must name at least one. Format 3 Check the magic file fileË-c[Ë-mËmagicfile] -c (check) The magic file, by default the system file /etc/magic, is checked for format errors. However, if the -m option is specified, the magic file magicfile is checked instead. 382 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc file -mËmagicfile (magic file) Causes file to check the alternate magic file magicfile for format errors. Mode of operation 7. Juli 2009 Stand 11:58.30 file performs a series of tests on each input file and attempts to classify it on the basis of its contents. If it appears to be a text file, file examines an initial segment (the first 512 bytes) and tries to guess the language it was created in. The accuracy of the guess cannot be guaranteed, however. If the input file is an executable program, it is identified as such, and further information is provided with respect to its contents. To do this, file searches the file for "magic numbers", i.e. for numeric constants or string constants that give an indication of the type of file. The file /etc/magic contains an explanation of these magic numbers. Output Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file writes its file classification to standard output. The following table lists the most important file types that file classifies: File Output Meaning ascii text ASCII text file block special Block special file c program text C source program character special Character special file commands text Shell script cpio archive Archive generated by cpio current ar archive Archive library (see ar) data Data file directory Directory executable Executable file (e.g. LLMs) empty file Empty file fifo FIFO file fortran program text FORTRAN source program tar archive Archive generated by tar, pax text EBCDIC text file /etc/magic File containing a key to the magic numbers U22794-J-Z125-6-76 383 file Locale The following environment variables affect the execution of file: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. The file list contains the following file names: dir letter lib.a prog.c The following command line will yield information on the contents of each classified file type: $ file -f list dir: letter: lib.a: prog.c: directory ascii text current ar archive c program text Thus dir is a directory, and letter contains normal ASCII text. lib.a is an archive library; prog.c contains a C program. The same output could also have been obtained with a command line reading: $ file dir letter lib.a prog.c See also 384 c89 [5] U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc find find find files find scans directories and all their subdirectories for files which match a specified search criterion. Files located in this way can be listed and/or processed with a command. find locates not only ordinary files, but also directories, special files and FIFOs. Syntax findËdirectoryËexpression directory Name of the directory that is to be scanned. find will search through this directory and recursively through its subdirectories, provided you have read and execute permission (r and x bit) for them. More than one directory may be named. expression expression may be given as one or more primary expressions (primaries) of the kind listed below or as a combination of these primaries. find applies expression to each file in the specified directories or subdirectories by evaluating primaries from left to right. Each primary is considered to have a "true" or "false" value for a file. The truth value of each expression and the next relational operator determine whether or not find will process the next primary. Most primaries define conditions, i.e. they return a value of true if the current file satisfies the condition. The expressions: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -print -exec command \; -ok command \; are not conditions. They cause actions to be executed, e.g. output of the file name or deletion of the file. When find processes one of these expressions, the associated action is always performed, regardless of whether the expression returns a value of true or false. If none of the above action primaries are specified, find exits with an error message. Shell metacharacters that appear in expression must be escaped to ensure that they are passed to find and not interpreted by the shell. Primaries as conditions The following section describes primaries; the method of combining primaries is shown thereafter. If you use options to find files with specific attributes (e.g. the files modified within a given period), the relevant option must come before the -print option (see below), as otherwise all files will be listed. In the following discussion, n represents a decimal integer; +n means "more than n", -n means "less than n", and n means "exactly n". U22794-J-Z125-6-76 385 find -nameËfile True if file matches the name of the current file. You can also use the usual shell metanotation for file name generation, but then file must be enclosed in single quotes, e.g. find /usr/adam -name ’group.*’ (see section “Metacharacters for the POSIX shell” on page 884). Only file basenames may be specified; pathnames such as text/tmp are not permitted. -permËmode True if the file permission flags exactly match mode (see section “chmod change file modes” on page 204). mode can also be an octal number. If mode is prefixed by a minus sign (-), only the bits that are set in mode are compared with the file permission flags, and the expression evaluates true if they match. -typeËcharacter True if the current file is of type character, where character can be: f ordinary file d directory b block special file c character special file l symbolic links p named pipe or FIFO file -fstypeËname True if the file system to which the current file belongs is of type name, where name can be ufs or some special file systems such as proc or fdfs. -linksË[+-]n True if there are (more/less than) n links to the current file. -inumË[+-]n True if the current file has an inode number greater than (+), less than (-), or equal to n. The expression -inum +n -inum -m can be used to find all inode numbers between n and m. -userËlogin_name True if the current file belongs to the user login_name. This option is only of use for users with uid=0 (command id). -nouser True if the current file belongs to a login name which is not present. This option is only of use for users with uid=0 (command id). -groupËgroup_name True if the current file belongs to the group group_name. 386 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc find -nogroup True if the current file belongs to a group that is not listed in the /etc/group file. -sizeË[+-]n[c] c not specified: True if the current file is (more / less than / equal) n blocks long, where one block is 512 bytes. c specified: True if the current file is (more / less than / equal) n bytes long. -atimeË[+-]n (access) True if the current file was last accessed (more / less than / equal) (n-1) to n*24 hours ago. The access time of directories searched by find is changed by find itself. -mtimeË[+-]n (modification time) True if the current file was last modified (more / less than / equal) (n-1) to n*24 hours ago. -ctimeË[+-]n True if the inode of the current file was last modified (more / less than / equal) (n-1) to n*24 hours ago. -newerËfile True if the current file is "newer" than the specified file, i.e. if it was created or modified at a later point in time. -local True if the current file physically resides on the local system. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -prune Always true. If this expression is processed no search is conducted in files or directories which lie below the current level in the file hierarchy. -xdev Always true. If this expression is processed no search is conducted in files or directories which lie below directories which have a different device number (st_dev, see the stat() function [4]). If -xdev is set then this applies to the entire expression even if -xdev is not normally processed. Action primaries -print Always true. If this expression is present, it causes find to print the path name of the current file on standard output. -execËcommandË\; command is executed as soon as this expression is processed. You must terminate command with a blank and an escaped semicolon (\;). U22794-J-Z125-6-76 387 find A set of braces {} can be used to represent the name of the current file. The expression -exec command \; is true if the executed command returns an exit status of 0. The truth value is significant when this expression is combined with other expressions. -okËcommandË\; Like -exec, except that find asks if the command is to be executed each time the expression is processed. The command is only executed if you respond with the character or string signifying "y[es]" in the current locale (see environment variable LANG). Expressions that affect the behavior of find -depth Always true. If present, this expression causes find to act upon entries in a directory before the directory itself. -follow Always true. This expression causes symbolic links to be followed. It should not be combined with the -type l expression. -mount Always true. If this expression is present, it causes find to restrict its search to the file system containing the directory specified. Combining expressions The expressions described above can be combined with one another as shown below. Please note the blanks used before and after the operators! The operators are listed in order of decreasing precedence. \(Ëexpression...Ë\) Parentheses group expressions together. The parentheses themselves must be escaped with a backslash, since they have a special meaning for the shell. !Ëexpression Negation, i.e. true if the expression evaluates to false. expressionËexpression Logical AND, i.e. true if both expressions are true. If the first expression is false, find does not process the second expression. Example If the second expression is -exec command \; the specified command will only be executed if the first expression is true. 388 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc find expressionË-oËexpression Logical OR, i.e. true when either of the expressions is true. If the first expression is true, find does not process the second expression. Example If the second expression is -exec command \; the command will only be executed if the first expression is false. Error Error messages without command termination (exit status 0) find: cannot read dir dir: Permission denied Since you have no read permission for the dir directory, this directory cannot be scanned. find does not terminate after this error message, but continues scanning directories for which you do have the required access permissions (r bit). find: cannot access dir/file: permission denied Since you have no execute permission (x bit) for dir, this directory cannot be scanned. find does not terminate after this message but searches through those directories for which you do have the appropriate perimissions (r and x bits). find: cannot open dir: No such file or directory There is no directory named dir. Error messages with command termination (non-zero exit status) find: missing conjunction You have either combined primaries incorrectly in the find call or specified more than one argument in a primary. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 find: no action specified You have not specified an action (print, exec, ok). find: incomplete statement You have forgotten the escaped semicolon \; which is required to terminate a command in an -exec or -ok expression. find: insufficient number of arguments You have specified too few arguments. find: path-list predicate-list You have failed to specify the pathname list for directory. File /etc/group File containing group names U22794-J-Z125-6-76 389 find Locale The following environment variables affect the execution of find: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements used in pattern matching notation for the -n option. In file name generation patterns in square brackets (such as find . -name ‘[[=a=]]*‘ -print), the LC_COLLATE environment variable governs the scope of character ranges, equivalence classes and collating elements. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments), the behavior of character classes in pattern matching notation for the -n option and the behavior of character classes within regular expressions. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 A simple example to illustrate how find works: Display the path names of all files that – are located in the current directory or in a subdirectory and – have the name tmp. $ find . -name tmp -print In this case, expression comprises two primaries that are linked by a logical AND operator. find first checks the -name tmp primary for each file. If this expression is true (i.e. the current file is named tmp), find will also process the expression -print, which outputs the path names. Otherwise, find does not process the -print expression and remains silent. Please note the sequence. If you entered: $ find . -print -name tmp instead, find would process the -print expression for each file, i.e. would output the path names of all files. 390 U22794-J-Z125-6-76 Example 2 A more complex example: Display the path names of all files that – are located in the current directory or its subdirectories, and – are named tmp or have names ending in .xx. $ find . \( -name tmp -o -name '*.xx' \) -print Please note the use of blanks between the arguments! 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc find find begins by processing the parenthesized specifications for each file. These comprise two primaries linked by a logical OR operator. find first tests the -name tmp primary. If this expression is true (i.e. if the current file is named tmp), find does not process the expression -name ’*.xx’ at all; this is because the result of the expression in parentheses will be true in any case. If -name tmp evaluates to false, find tests the second primary, i.e. -name ’*.xx’. If this expression is true (i.e. the file name ends in .xx), the parenthesized expression will also evaluate to true; otherwise, the result of the expression in parentheses is false. If the parenthesized expression is true, find then processes the -print expression, i.e. outputs the file names (AND operator; see Example 1). If false, find does not process the -print expression, i.e. remains silent. Example 3 Search all entries in the /usr/santaclaus directory and its subdirectories and print the files not owned by santaclaus. $ find /usr/santaclaus ! -user santaclaus -print Example 4 Delete all files that, – are named tmp or have names ending in .xx, and – have not been accessed for more than 7 days. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Confirmation is to be requested before the removal of each file. $ find / \( -name tmp -o -name '*.xx' \) -atime +7 -ok rm {} \; Example 5 Recursively print all file names in the current directory and below, but skipping all SCCS directories: $ find . -name SCCS -prune -o -print See also chmod, ln, test stat() [4] U22794-J-Z125-6-76 391 fold fold filter for folding lines fold folds the lines of text files or the standard input so that they do not exceed the preset or specified line length. The default presetting is 80 characters per line. The lines are folded through the insertion of a newline character so that each output line (termed "segment" in the following) does not exceed the preset or specified line length (or does not exceed the maximum number of bytes). However, lines are not folded in the middle of a character. Behavior is not predictable if number is smaller than the number of columns which may be occupied by a single input character. If a carriage return, backspace or tab is read in the input and the option -b is not set then the input is considered to be a character: Backspace The current line length is reduced by one. However, it cannot assume a negative value. fold does not insert a newline character either immediately before or after a backspace. Carriage return The current line length is set to zero. fold does not insert a newline character either immediately before or after a carriage return. Tab All tabs that are read move the column position pointer to the next tab stop position. Tab stop positions are located at all column positions n where: n modulo 8 is equal to 1. ! Syntax Caution! If the input lines contain underscores then fold may react incorrectly. fold[Ë-bs][Ë-wËwidth][Ëfile...] No option specified fold folds the input lines so that no line exceeds a maximum width of 80 characters (default). option -b (bytes) The line length is calculated in bytes not column positions. -s (segment) If a line segment contains a blank within the first number of column positions (or bytes) then the line is folded after the last space which fulfils the number condition. If no space which fulfils this condition exists then the -s option is ineffective for this input line. 392 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fold -wËwidth (width) Defines the maximum width of a line, where width is the number of characters per line. width should be a multiple of 8 if tabs are present in the input line. file 7. Juli 2009 Stand 11:58.30 Name of the text file to be folded. You may name several such files, in which case the specified options will be applied to each file. file not specified: fold reads from standard input. Locale The following environment variables affect the execution of fold: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), and for the determination of the width in column positions each character would occupy on a constant-width font output device. Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 LC_MESSAGES U22794-J-Z125-6-76 393 fold Example Printing a file named notes on standard output. The following result is obtained with the cat command: $ cat Notes: Remind Carl to send in a bid within the next two weeks. The new deadline for the evaluation of all bids is the end of June. Using the fold command, you have the option of redefining the length of the output lines. The following command folds the contents of the notes file so that each line has a maximum width of 40 characters: $ fold -w 40 notes Notes: Remind Carl to send in a bid within the next two weeks. The new deadline for the evaluation of all bids is the end of Jun e. See also 394 pr U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fsck fsck file system check fsck checks file systems for inconsistencies and corrects these interactively with the user. The user’s agreement is requested before any corrective measures are implemented. Any inconsistencies other than those mentioned above may result in data loss. Diagnostic messages provide information about the extent and seriousness of such losses. fsck automatically corrects less serious inconsistencies such as unreferenced inodes, excessive reference counter values in inodes, missing blocks in the free blocks list, blocks which simultaneously appear in the free blocks list and in files or incorrect superblock counters. A message is output for each inconsistency which is corrected. This message displays the type of correction and the file system in which it was performed. After the file system has been corrected, fsck outputs the number of files in the file system, the number of occupied and free blocks and the corresponding percentage values. By default, the command waits for the user’s response, which must be either yes or no, before performing any correction. If the user does not possess write permission for the file system then fsck defaults to -n (no correction). The command checks for the following inconsistencies: 1. Blocks claimed by multiple inodes or the free block list. 2. Blocks which are claimed by multiple inodes or the free block lits and which lie outside the file system. 3. Incorrect reference counters. 4. Incorrect directory sizes. 5. Incorrect inode formats. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 6. Blocks which are not listed anywhere. 7. Directory checks, files which point to an unassigned inode, inode numbers outside the allocated range, omission of ’.' and ’..' as the first directory entry. 8. Superblock checks: More blocks for inodes than are present in the file system. 9. Incorrect format for free block list. 10. Total of free blocks and/or free inodes incorrect. If the user agrees, orphaned files or directories (i.e. allocated but unreferenced) are relinked through being written to the lost+found directory. The allocated name corresponds to the inode number. If the lost+found directory does not yet exist it is created at this point. If not enough space is available, the directory is extended. U22794-J-Z125-6-76 395 fsck To designate a file system you may specify the name of the block or character-oriented device on which it is located or the name of the mountpoint. Syntax fsck[Ë-FËufs|UFS][Ë-y|-n|-m][[Ëspecial_file ...] The following options are possible: -FËufs|UFS Specifies ufs as the file system type. -y All inconsistencies are checked. The questions asked by fsck are answered with "yes". -n All inconsistencies are checked. The questions asked by fsck are answered with "no". -m The status in the file system’s superblock is checked. This option ensures that the file system is suitable for mounting. special_file special_file represents a block or character special device (for example, /dev/dsk/234). It is preferable to use a character special device. fsck cannot be applied to mounted block special devices. special_file not specified: fsck looks through the /etc/vfstab file and executes fsck for all the character special devices in the fsckdev field of /etc/vfstab for which there is a numeric entry in the fsckpass field. Hint In almost all cases it is quicker to examine character-oriented devices. For file systems which were mounted with a journal, the –m option is also sufficient to place the file system in a consistent status in a very short time after a system crash. The check of all the inconsistencies, on the other hand, can take a very long time depending on the size and utilization level of the file system. The fsck command is not supported for bs2fs file systems. File lost+found /etc/vfstab List of default parameters for each file system See also 396 mount, mountall, umount U22794-J-Z125-6-76 fsexpand expand existing file systems fsexpand enables file systems to be expanded by PAM pages or cylinder groups. The file systems may not be mounted. Syntax fsexpand[Ë-i][Ë-pËpam pages|Ë-cËcylinder groups]Ëdevice The following options are possible: 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc fsexpand -i Outputs file system information. Output takes place to stdout. In particular information is output on how ideal an expansion is, e.g. to prevent unused PAM pages in the expanded file system. In conjunction with the -p or -c option, information is output before the expansion (source file system) and after the expansion (target system). -pËpam pages Expansion of a file system by PAM pages. The file system is expanded by the specified number of PAM pages. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -cËcylinder groups Expansion of a file system by cylinder groups. The file system is expanded by the specified number of cylinder groups. The size of a cylinder group in the source file system can be ascertained before expansion using fsexpand -i. Up to a file size of a little more than 2 GB, the size is 2048 PAM pages. From 2 GB on, the size increases. With a file size of 4 GB, for example, it is then 4096 PAM pages. device Device name /dev/rdsk/... (character-oriented device only, i.e. not /dev/dsk) or BS2000 file name. device must be writeable when an expansion is to take place. If the file system is located on the HOME pubset, the BS2000 file name (with or without catid) must match the notation in the /etc/partitions file. Hints The fsexpand command is not supported for bs2fs file systems. A file system is expanded in two steps: 1. Physical expansion 2. Combining (administration) units of the file system (known as cylinder groups) to form larger units (compactification) Compactification is performed only if the expanded file system is greater than 2 GB and at least double the size of the original file system. U22794-J-Z125-6-76 397 fsexpand Compactification requires a considerable amnount of the runtime for fsexpand. If, for example, a file system which is 1 GB in size is expanded by a value which is only slightly above 1 GB (i.e. with compactification), the runtime is extended by a factor of 3 - 4 compared to expansion by a value which is slightly less than 1 GB (i.e. without compactification). However, compactification has the advantage that considerable gains in performance can be achieved when the file system is used because at runtime the requirement for memory and CPU time is lower thanks to the administration units being combined. Example $ fsexpand -i ’$BACH.BACH.TEST device /dev/rdsk/8 in Containerfile: $BACH.BACH.TEST size of BS2000 Containerfile (PP): 12288 last page used in Containerfile (PP): 12288 size used for POSIX filesystem (PP): 12288 unused in Containerfile (PP): 0 Cylindergroups in filesystem: 6 Cylinders in cylindergroup (PP): 16 size of a cylindergroup (PP): 2048 inodes per cylindergroup: 2048 inodes total: 12288 datablocks (4K) in filesystem: 5731 free blocks directories free inodes 1853 4 12232 optimal values for expansion of container: 0 PP + N * 2048 PP 398 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdof.doc ftyp ftyp define file processing mode (BS2000) ftyp determines whether files are interpreted as text or binary files when copied between BS2000 and the POSIX file system using bs2cp. The command is only effective for SAM files and for text-type PLAM library elements (element type other than LLM). PAM files and LLMs are always interpreted as binary files and ISAM files are always interpreted as text files. If no ftyp command is entered, all SAM files are interpreted as text files. Syntax ftyp[Ë-h][Ëtext|binary|textbin] No option specified The text option is used. option -h Prints out the command syntax with an explanation of the options. text SAM files and text-type library elements are to be interpreted as text files. Given this setting, the following conversions are performed when writing to the BS2000: POSIX BS2000 Tab character (x´05´) Corresponding number of spaces to tab position Newline character (x´15´) Line change (Record change) Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 When a file is read from the BS2000 a newline character is appended to each record which is read (x´15´). i This option can not be used for SAM files with fixed record length. binary SAM files are to be interpreted as binary files. No conversions are performed. i U22794-J-Z125-6-76 This option can also be used for SAM files with fixed record length. In this case the last record is padded out with binary zeros. 399 ftyp textbin SAM files and text-type library elements are to be interpreted as binary text files. Given this setting, the following conversions are performed when SAM files are written to the BS2000: POSIX BS2000 Newline character (x´15´) Line change (record change) Tabs are not converted. When a file is read from the BS2000 a newline character is appended to each record which is read (x´15´). i Example This option can not be used for SAM files with fixed record length. The input file of the POSIX file system should be transferred to the BS2000 as a binary file. $ ftyp binary $ bs2cp input bs2:output See also 400 bs2cp, bs2file U22794-J-Z125-6-76 gencat generate a formatted message catalog The gencat utility merges the contents of a message text source file into a binary encoded message catalog. The message catalog is created if it does not already exist. If it does exist, its messages are included in the new message catalog. If the set numbers and message numbers of existing and newly defined message texts match, gencat replaces the old message texts currently contained in the message catalog with the new message texts defined in the message text file. 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc gencat Message catalogs produced by gencat are binary encoded, which means that their portability cannot be guaranteed between different types of machine. Thus, just as C programs need to be recompiled for each type of machine, message catalogs must be recreated with gencat. A message text source file can contain either set and message numbers or simply message numbers. In the later case, the set NL_SETD is assumed for the set numbers. Syntax gencat[Ë-lm]Ëcatfile[Ëmsgfile...] option -l If catfile already exists, information on messages contained in it will be written to standard output in the following format: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 SET set_num, MESSAGE mesg_num, OFFSET offset, LENGTH msg_len, message_txt * offset indicates the distance from the beginning of the file to the start of the message text, i.e. – first message: offset (1) = 0 – n th message: offset (n) = offset (n-1) + msg_len (n) -m The -m option ensures compliance with the X/Open Standard. The -m option is supplied for compatibility with previous versions of gencat released in a number of specialized internationalization products. This option will cause gencat to build a single file catfile which is compatible with the format catalogs produced by the earlier versions. The retrieval routines detect the type of catalog they are using and act appropriately. The -m option corresponds to the default behavior of gencat and need not be explicitly set. U22794-J-Z125-6-76 401 gencat No option specified gencat behaves as described under the -m option. catfile Name of the binary encoded message catalog that gencat is to generate from the message text file msgfile. If a dash (-) is specified for catfile, gencat prints to standard output. msgfile Name of the message text source file. gencat generates a binary encoded message catalog from this file. If a dash (-) is specified for msgfile, gencat reads from standard input. More than one message text file may be specified. Format of a message catalog A message catalog created by gencat with the option -m contains the following structures in the given order: 402 ● The catalog header, CAT_HDR, consisting of: – the file's magic number – the number of sets in the message file – the space (in bytes) needed to load the file, excluding the length of the file header – the position at which the message headers begin, excluding the length of the file header – the position at which the message texts begin, excluding the length of the file header ● A set header, CAT_SET_HDR, for each existing set. This header consists of: – the set number – the number of messages in the set – the initial offset in the table ● A message header, CAT_MSG_HDR, for each existing message. This header consists of: – the message number – the length of the message in bytes – the message offset in the table ● The individual message texts, delimited by \0. U22794-J-Z125-6-76 Locale 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc gencat The following environment variables affect the execution of gencat: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. Generating a binary encoded message catalog en_wc.cat from the English message text file en_wc.msf for the wc command. The contents of the message text file are as follow: 1 wc: cannot open %s \n 2 together \n 3 Syntax: wc[Ë-c|Ë-m][Ë-lw][Ëfile...] \n The following command generates the message catalog: See also iconv catopen(), catgets(), catclose(), limits.h, nl_types.h [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 $ gencat en_wc.cat en_wc.msf U22794-J-Z125-6-76 403 getconf getconf get configuration values In the first synopsis form, getconf writes the value of the variable specified by the system_var operand to the standard output. In the second syntax form, getconf writes the value of the variable specified by the path_var operand to the standard output. This value is valid within the path specified by the pathname operand. The value of each configuration variable is output as if it were determined by calling the function from which it was defined. The value reflects the conditions in the current execution environment. If the specified variable is valid, but is not defined on the system, getconf writes %undefined to the standard output. Syntax Format 1: getconfËsystem_var Format 2: getconfËpath_varËpathname Format 1 getconfËsystem_var system_var Name of a configuration variable whose value can be obtained using the confstr() or sysconf() functions [4]. All of the values listed in the following table are supported: 404 ARG_MAX NL_TEXTMAX POSIX2_C_DEV BC_BASE_MAX OPEN_MAX POSIX2_C_VERSION BC_DIM_MAX _POSIX_ARG_MAX POSIX2_EXPR_NEST_MAX BC_SCALE_MAX _POSIX_CHILD_MAX POSIX2_FORT_DEV BC_STRING_MAX _POSIX_JOB_CONTROL POSIX2_FORT_RUN CHAR_BIT _POSIX_LINK_MAX POSIX2_LINE_MAX CHAR_MAX _POSIX_MAX_CANON POSIX2_LOCALEDEF CHAR_MIN _POSIX_MAX_INPUT POSIX2_RE_DUP_MAX CHILD_MAX _POSIX_NAME_MAX POSIX2_SW_DEV CLK_TCK _POSIX_NGROUPS_MAX POSIX2_UPE COLL_WEIGHTS_MAX _POSIX_OPEN_MAX POSIX2_VERSION CS_PATH _POSIX_PATH_MAX RE_DUP_MAX EXPR_NEST_MAX _POSIX_PIPE_BUF SCHAR_MAX INT_MAX _POSIX_SAVED_IDS SCHAR_MIN INT_MIN _POSIX_SSIZE_MAX SHRT_MAX LINE_MAX _POSIX_STREAM_MAX SHRT_MIN U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc getconf LONG_MAX _POSIX_TZNAME_MAX SSIZE_MAX LONG_MIN _POSIX_VERSION STREAM_MAX MB_LEN_MAX POSIX2_BC_BASE_MAX TZNAME_MAX NGROUPS_MAX POSIX2_BC_DIM_MAX UCHAR_MAX NL_ARGMAX POSIX2_BC_SCALE_MAX UINT_MAX NL_LANGMAX POSIX2_BC_STRING_MAX ULONG_MAX NL_MAX POSIX2_CHAR_TERM USHRT_MAX NL_MSGMAX POSIX2_COLL_WEIGHTS_MAX NL_SETMAX POSIX2_C_BIND CHARCLASS_NAME_MAX NL_TEXTMAX _XOPEN_VERSION LONG_BIT NZERO _XOPEN_XCU_VERSION NL_ARGMAX TMP_MAX _XOPEN_XPG2 NL_LANGMAX WORD_BIT _XOPEN_XPG3 NL_MAX _XOPEN_CRYPT _XOPEN_XPG4 NL_MSGMAX _XOPEN_ENH_I18N NL_SETMAX _XOPEN_SHM The symbol PATH is also recognized. It returns the same value as the confstr() [4] value CS_PATH. getconf also recognizes the variables LOGNAME_MAX, PAGE_SIZE, PAGESIZE and PASS_MAX . All variable names can be specified with or without a leading underscore (_). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 i U22794-J-Z125-6-76 405 getconf Format 2 getconfËpath_varËpathname path_var Name of a configuration variable whose value can be obtained using the pathconf() [4] function. All of the values listed in the following table are supported: LINK_MAX NAME_MAX _POSIX_CHOWN_RESTRICTED MAX_CANON PATH_MAX _POSIX_NO_TRUNC MAX_INPUT PIPE_BUF _POSIX_VDISABLE All variable names can be specified with or without a leading underscore (_). i pathname Pathname for which the variable specified by path_var is to be determined. Locale The following environment variables affect the execution of getconf: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Exit status 406 Determine the location of message catalogs for the processing of LC_MESSAGES. The following exit values are returned: 0 The specified variable is valid and information about its current status was written to the standard output. >0 An error occurred. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc getconf Example 1 In this example, the value of {NGROUPS_MAX} is obtained (Format 1): $ getconf NGROUPS_MAX 16 Example 2 In this example, the value of {NAME_MAX} is obtained for a specific directory (Format 2): $ getconf NAME_MAX /usr 255 Example 3 This example shows how to deal more carefully with results that mightbe unspecified: if value=$(getconf PATH_MAX /usr); then if [ “$value“ = “undefined“ ]; then echo PATH_MAX in /usr is infinite. else echo PATH_MAX in /usr is $value. fi else echo Error in getconf. fi Note that the following calls in a C program could return different results: sysconf(_SC_POSIX_C_BIND); and: system(“getconf POSIX2_C_BIND“); See also pathconf(), confstr(), sysconf() [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The sysconf() [4] call returns a value that corresponds to the conditions when the program is either compiled or executed. The system() [4] call to getconf always returns a value that corresponds to the conditions when the program is executed. U22794-J-Z125-6-76 407 getopts Built-in sh command getopts parse utility options The POSIX shell built-in getopts is used by shell scripts to parse arguments and options in the command line and to check for valid options. It supports all applicable rules of the command syntax standard. You can use getopts in shell procedures to analyze the arguments specified when the procedure is called. The individual options and arguments are stored in sequence in shell variables and can then be easily queried or checked. If an option in the argument list is not permitted or if getopts finds no corresponding argument for an option which requires an argument then getopts issues a corresponding error message. The argument list should always be processed using getopts and examined for valid options in order to ensure that all procedures and commands process the argument list in the same way. Syntax getoptsËoptstringËname[Ëarg]... optstring A string which may consist of letters and colons : . The letters specified in optstring are considered by getopts to be permitted shell procedure options. If a letter is followed by a colon then getopts expects an argument or a group of arguments for this option. Any arguments must be separated from the option by spaces or tabs. name Name of the shell variable in which getopts places the next option each time it is invoked. argË... Argument list parsed by getopts. arg not specified: getopts parses the argument list of the command line with which the script was invoked. 408 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc Built-in sh command getopts Mode of operation Each time it is invoked, getopts places the next option in the shell variable name and the index of the next argument to be processed in the shell variable OPTIND. Whenever the shell command interpreter or a shell script is invoked, OPTIND is initialized to 1. In the case of options which require an argument, this argument is assigned to the shell variable OPTARG. Options which require an argument must be identified by a colon : in optstring. If no option is present or if the option has no argument then OPTARG is reset. If an invalid option is identified then a question mark ? is assigned to the shell variable name. Invalid options are those which are not present in optstring. In this case (if the first character in optstring is a colon :) the located option character is assigned to the shell variable OPTARG. However, no output is written to the standard error output. Otherwise the shell variable OPTARG is reset and a message is written to the default error output. This is interpreted as a detected error in the argument presentation for the calling function. It is, however, not a getopts error. If an option argument is missing, then: – If the first character of optstring is a colon :, the shell variable specified in name is set to the colon and the shell variable OPTARG is set to the detected option character. – Otherwise the shell variable specified in name is set to the question mark, the shell variable OPTARG is reset and a message is written to the standard error output. This is interpreted as a detected error in the argument presentation for the calling function. It is, however, not a getopts error. A message is output as indicated but the exit status is zero. Changing the value of the shell variable OPTIND or invoking getopts with different sets of arguments may lead to unexpected results. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 When the end of the option list is encountered, getopts exits with a non-zero exit status. The special option -- may be also used to identify the end of the options. U22794-J-Z125-6-76 409 getopts Locale Built-in sh command The following environment variables affect the execution of getopts: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. The following fragment of a shell script scrpt shows how you might process the arguments for a script that can take the options -a or -b, as well as the option -o, which requires an option argument. Options -a and -b are mutually exclusive, and if both are specified, only the one listed second applies: while getopts abo: c do case $c in [ab]) o) \?) FLAG=$c;; OARG=$OPTARG;; echo "usage: $0 [-a| -b] [-o ]" exit 2;; esac done shift `expr $OPTIND - 1` This code accepts any of the following invocations of scrpt as equivalent: proz -a -b -o "xxx z yy" file proz -a -b -o "xxx z yy" -- file proz -ab -o "xxx z yy" file 410 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc grep grep search a file for a pattern grep reads lines from one or more text files or from standard input and compares these lines with a specified pattern. Unless told otherwise (by options), grep copies every line that matches the pattern to standard output. grep permits the use of simple regular expressions in the specified pattern (see section “Regular POSIX shell expressions” on page 877). If you specify more than one input file, the relevant file name will be displayed before each output line. Syntax Format 1: grep[Ë-E|Ë-F][Ë-c|Ë-l|Ë-q][Ë-bihnrsvxy]Ë-eËpatternlist[Ë-fËpatternlist] [Ëfile...] Format 2: grep[Ë-E|Ë-F][Ë-c|Ë-l|Ë-q][Ë-bihnrsvxy][Ë-eËpatternlist]Ë-fËpatternfile [Ëfile...] Format 3: grep[Ë-E|Ë-F][Ë-c|Ë-l|Ë-q][Ë-bihnrsvxy]Ëpatternlist[Ëfile...] The formats are described together since the patterns which grep uses to compare the input lines are specified either via patternlist or using the option -e patternlist or -f patternfile. No option specified grep outputs all lines that match the given pattern. If you specify more than one input file, each output line will be preceded by the name of the file in which the line was found. option -E (E - extended) grep treats each pattern as an extended regular expression.Option -E is equivalent to the egrep command. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -F (F - fast grep) grep searches for strings. Option -F is equivalent to the fgrep command. -c (count) grep outputs only the number of lines found (i.e. the lines that grep would have displayed without the -c option, see Example 3); the lines themselves are not displayed. -l (list) grep simply outputs the names of files that contain at least one of the matching lines. (These are the lines that egrep would output if the -l option were omitted, see Example 4 on page 415.) Each file name is printed just once. The lines themselves are not displayed. -q (quiet) grep writes nothing to the standard output even if matching lines are found. -b (block) Each output line is preceded by the number of the block in which it was found. Each file is made up of 512-byte blocks which are numbered consecutively from 0. The -b option is sometimes useful in locating disk block numbers by context (see the offset argument for the od command on page 584, for example). U22794-J-Z125-6-76 411 grep -i or -y (ignore) when performing comparisons, grep does not distinguish between uppercase and lowercase. -h (hidden) When searching multiple files, grep does not write the file name before each output line. -n (number lines) Each output line is preceded by its line number in the relevant input file. Line numbering starts at 1. If grep is reading from standard input, the line number refers to the standard input. -r (recursive) Names that refer to directories are processed recursively; in other words, all the files and subdirectories in that directory are scanned as well. -s (silent) Error messages produced for non-existent files or files which the user is not authorized to read are suppressed. -v (vice versa) grep outputs all lines that do not match the specified pattern. In conjunction with option -c: grep prints only the number of lines that do not match. In conjunction with option -l: grep only outputs the names of files containing such lines. -x (x - exact) fgrep only outputs lines which contain one of the specified strings and no other characters. -eËpatternlist (e - expression) You need to set this option when the first expression in patternlist starts with a hyphen -. When -e is set, such a pattern list is not interpreted as an option but as a list of patterns with which egrep is to compare the input lines. -fËpatternfile (f - file) egrep reads the list of patterns from the file patternfile. Every line in patternfile is interpreted as an extended regular expression. patternlist A simple regular expression to be used by grep when searching for matching input lines (see section “Regular POSIX shell expressions” on page 877). If patternlist contains characters that have a special meaning for the shell, you must enclose it in single quotes: ’patternlist’. file Name of the file that grep is to scan. You may name any number of files. file not specified: grep reads its input from standard input. 412 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc grep i grep can only be applied to text files. Applying grep to binary files (history files, for example) will produce an undefined result, because the occurrence of a null byte logically terminates an input line. grep, fgrep and egrep 7. Juli 2009 Stand 11:58.30 The grep, fgrep and egrep commands perform similar functions and are largely identical in terms of usage. The following section lists the most important differences between these commands. grep processes simple regular expressions. fgrep processes strings only. However, you may specify several strings in one call. The strings can either be entered directly in the command line, separated by newline characters, or passed to fgrep from within a file. fgrep is fast and compact and can search for a large number of strings. All specified strings are searched for in each individual line. egrep processes extended regular expressions. Among other things, these include all simple regular expressions with one exception: the \(...\) construct used in simple regular expressions does not have a special meaning in extended regular expression syntax and is hence not processed by egrep. Several regular expressions can be specified together, separated by newline characters. egrep interprets these newline characters as an OR operator (the vertical bar character; see section “Regular POSIX shell expressions” on page 877). The regular expressions can either be specified directly in the command line or passed to egrep via a file. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of grep: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. LC_CTYPE U22794-J-Z125-6-76 Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files) and the behavior of character classes within regular expressions. 413 grep LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. Determine the location of message catalogs for the processing of LC_MESSAGES. NLSPATH Exit status Example 0 Lines found 1 No line found >1 Syntax error or “Cannot open file”. This exit status remains valid even if lines have been found in other input files. The files customer1 and customer2 will be used as a basis for all following examples. Their contents are given below: customer1: 080685 120387 180588 999.98 1240.25 330.87 20 Units 3 Units 1 Units Item Item Item 038 023 332 Johnson Ltd. Skinner Ltd. Skinner Ltd. customer2: morrow lance, 86 sherwood street, london w1 skinner robert, 16 garden hill, london ec3 Example 1 Output lines that match a specified pattern (without an option and with option -i): $ grep Skinner customer1 customer2 customer1:120387 1240.25 3 Units customer1:180588 330.87 1 Units Item Item 023 332 Skinner Ltd. Skinner Ltd. If you also wish to display lines containing the word skinner in lowercase you enter: $ grep -i skinner customer1 customer2 customer1:120387 1240.25 3 Units Item 023 Skinner Ltd. customer1:180588 330.87 1 Units Item 332 Skinner Ltd. customer2:skinner robert, 16 garden hill, london ec3 More complicated patterns can be set up with the help of regular expressions, e.g.: Display all 1994 entries from the file customer1; these are lines that contain the number 94 in columns 5 and 6: $ grep '^....94' customer1 120394 1240.25 3 Units Item 414 023 Skinner Ltd. U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdog.doc grep Example 2 Output lines that do not match the specified pattern (option -v): $ grep -v '^1' customer1 customer2 customer1:080685 999.98 20 Units Item 038 Johnson Ltd. customer2:morrow lance, 86 sherwood street, london w1 customer2:skinner robert, 16 garden hill, london ec3 Example 3 Display the number of found lines (option -c): First display the number of lines that start with 1 for each input file. $ grep -c '^1' customer1 customer2 customer1:2 customer2:0 The number of lines that do not start with 1 are to be displayed next. $ grep -c -v '^1' customer1 customer2 customer1:1 customer2:2 Example 4 Display file names only (option -l): The names of files containing lines that begin with a 1 are to be output first. $ grep -l '^1' customer1 customer2 customer1 The names of files containing lines that do not start with 1 are displayed next. $ grep -l -v '^1' customer1 customer2 customer1 customer2 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Example 5 Display found lines with their line numbers (option -n): $ grep -n -i skinner customer1 customer1:2:120387 1240.25 customer1:3:180588 330.87 customer2:2:skinner robert, 16 See also customer2 3 Units Item 023 Skinner Ltd. 1 Units Item 332 Skinner Ltd. garden hill, london ec3 ed, egrep, fgrep, sed, stdio [4] U22794-J-Z125-6-76 415 hash hash Built-in sh command remember or report utility locations The POSIX shell built-in hash has two functions: – it can write the contents of the hash table on standard output or enter the specified command in the hash table (Format 1), – it can delete the contents of the hash table (Format 2). Each shell maintains its own hash table, in which it enters all commands that are invoked under their basic file names (basenames). Whenever you invoke a command under its basename, the shell first searches the hash table for your command. This accelerates the search process. If the command is not yet in the hash table of the current shell, it is entered there. When you start a subshell, its hash table is empty. When you terminate the subshell, the parent shell returns with its own hash table, and the hash table of the subshell is deleted. Syntax Format 1: hash[Ëname]... Format 2: hashË-r Format 1 Display or extend hash table hash[Ëname]... name Basename of a command, an executable shell script, or an executable program. The shell searches for this file by examining the contents of the PATH variable. When the file is found, the following information is passed to hash: – the appropriate relative path name in the form ./name if the current directory is assigned to the PATH variable and contains name, or – the absolute path name. The hash command enters this path name into the hash table. If name is not present in any of the directories assigned to the PATH variable, an error message is issued. The following cannot be specified for name: – shell scripts for which you have no execute permission. – commands with a name that includes a slash. This means that you cannot enter absolute or relative path names. – shell built-ins, since they are subroutines of sh and thus do not have names that represent executable files. By the same token, executable shell scripts and commands are not entered in the hash table unless they are invoked under their basenames. name not specified: 416 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoh.doc Built-in sh command hash The hash command writes the contents of the hash table on the standard output. The output can, for example, be structured as follows: ls=/usr/bin/ls cat=/usr/bin/cat chmod=/usr/bin/chmod Format 2 Delete hash table hashË-r -r Deletes the contents of the hash table. If you modify the value of the PATH variable, the contents of the hash table are automatically deleted. When you terminate the current shell, the hash table associated with this shell is also deleted. You should always delete the contents of the hash table in the current shell in the following circumstances: You have created an executable file in a directory dira whose path name is assigned to the PATH variable. Some other directory dirb, also specified in PATH, already contains an identically named command file which already appears in the current hash table. In this case the shell will always execute the older command, even if its directory (dirb) comes after the first one (dira) in the PATH variable. Deleting the hash table with hash -r will cause the shell to execute the first command it finds the next time either of these commands is invoked. In other words, the sequence of the entries in the PATH variable will be the determining factor. The path name of the first command found is now entered into the hash table, i.e. your command will always be executed from now on when you invoke it under its basename. name: not found This error message may be produced for any of the following reasons: – name is not contained in any of the directories whose respective paths have been entered in the PATH variable. – name is actually contained in one of these directories, but is not executable. – name is a shell built-in or a shell function. Variable PATH Search path of the shell Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Error U22794-J-Z125-6-76 417 hash Locale Built-in sh command The following environment variables affect the execution of hash: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 Display the contents of the hash table: $ echo $PATH /bin:/usr/bin:. $ hash cat=/usr/bin/cat ls=/usr/bin/ls Example 2 Add a command to the hash table: $ hash cat $ hash cat=/usr/bin/cat The command /usr/bin/cat is now a new entry in the hash table. 418 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoh.doc Built-in sh command hash Example 3 The following excerpt from a session demonstrates when the hash table is cleared: $ hash cat=/usr/bin/cat ls=/usr/bin/ls $ sh $ hash $ cp ... $ ls ... $ hash cp=/usr/bin/cp ls=/usr/bin/ls $ exit $ hash cat=/usr/bin/cat ls=/usr/bin/ls Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 The hash table in the new subshell is empty. When the subshell is terminated, the hash table of the parent shell becomes valid again, while that of the subshell is deleted. U22794-J-Z125-6-76 419 hd hd hex dump hd prints the contents of files in hexadecimal, octal or decimal notation or as character strings. It can also display the position of characters within a string. Syntax hd[Ë-format]...[Ë-A][Ë-t][Ë-sËoffset[*][wlbk]][Ë-nËcount[*][wlbk]][Ëfile]... If no format, offset, and count is specified: The output is identical to that of hd -abx -A, i.e. addresses and bytes are shown in hexadecimal. In addition, all bytes that represent printable characters are shown as such, and non-printing characters are represented by a dot. Addresses are displayed at the beginning of each line, followed by the hexadecimal representation of the bytes in the next few columns and the actual characters (with dots if required) on the right. Addresses are calculated relative to the start of the file. If no file is specified, the standard input is read; otherwise, the contents of all specified files are listed. -format Format that determines how individual byte blocks are to be interpreted and output (see “Format description” on page 421). -A (ASCII) All printable characters appear unaltered; non-printing characters are represented by a dot. The characters are shown in the column to the right of the first output format. -t (text) If this option is set, hd will ignore all format options that do not affect addresses. Each text line is printed with the address shown at the start of the line. Long lines are folded (split). The notation for control characters (values 0x00 to 0x1f) is a caret followed by the corresponding character (^@ to ^_). Bytes with the high order bit set are shown with a preceding tilde (~), but without the high order bit itself. The caret, tilde and backslash characters are preceded by a backslash in the output. Some special cases are represented by numeric values, e.g. a 7-bit DELETE (127) character as \177, and an 8-bit DELETE (255) as \377, respectively. -sËoffset[*][wlbk] Relative address at which printing of the file is to begin. If you do not specify a file or if you supply the input via a pipeline, a corresponding number of bytes will be skipped. hd will abort processing of the current file if you give it an invalid address. The relative address consists of a number, which can be specified in decimal, hexadecimal (preceded by 0x) or octal (preceded by 0), and optionally a flag indicating a unit size directly after the number. The possible flags are: 420 w 2-byte units (i.e. one word) l 4-byte units (i.e. one long word) b 512-byte units (i.e. half of one Kbyte) k 1024-byte units (i.e. one Kbyte) U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoh.doc hd You can mark the difference between a hexadecimal number that includes the digit b and the b flag by putting an asterisk (*) between the hexadecimal number and the b flag. The following examples show how the offset can be specified: -s 111 (111 bytes), -s 124l (496 bytes), -s 0xa*b (5120 bytes), -s 011k (9216 bytes). -sËoffset[*][wlbk] not specified: The output begins at the start of the file. -nËcount[*][wlbk] Number of bytes to be dumped. The count is specified in the same format as the offset, i.e. in decimal, hexadecimal or octal, followed by an optional w, l, b or k flag (see the -s option). file Name of the file to be dumped by hd. More than one file may be named. file not specified: hd reads input lines from standard input. Format description A format consists of the following components: – the byte block option (a, b, c, l or w) and – the method by which a byte block is to be interpreted in the output, i.e.: hexadecimal (x), decimal (d) or octal (o). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 All specified interpretation methods are applied to all specified byte blocks in a format. Format options can be combined and repeated to display addresses, characters, words, etc. in various ways. For example, you could combine -ax -bx into -abx, or specify -cxdo to show all characters in hexadecimal, decimal, and octal. Byte block options a (address) Format option for addresses. Addresses are only interpreted by one method, i.e. in hexadecimal, octal, or decimal. The address is always shown at the start of each line to be displayed, or in the first line of an output block if multiple lines are required for the formats. b (byte) Format option for byte. c (character) Format option for characters. All printing characters are displayed. C-language escape sequences are output as defined in the language; all other characters are shown in octal, hexadecimal or decimal, depending on the interpretation method. l (long word) Format option for 4 bytes. w (word) Format option for 2 bytes. U22794-J-Z125-6-76 421 hd Interpretation methods x (hexadecimal) hd interprets addresses or byte blocks as hexadecimal numbers. d (decimal) hd interprets addresses or byte blocks as decimal numbers. o (octal) hd interprets addresses or byte blocks as octal numbers. Without an interpretation method, but with a byte block option: The format is interpreted as -xdo. With no byte block option except for addresses: hd uses -bx in addition to the specified address format. Without a byte block option, but with an interpretation method: The format is interpreted as -acbwl. -format not specified: hd acts as if hd -abx -A were specified. See also 422 od U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoh.doc head head copy the first part of files head copies the opening lines of a file to standard output. If no file is given, head reads from standard input. Syntax Format 1: head[Ë-nËnumber][Ëfile] Format 2: head[Ë-number][Ëfile] Format 1 head[Ë-nËnumber][Ëfile] -nËnumber Number of lines to be output. number must be a positive decimal number. The space Ë between -n and number is optional. -nËnumber not specified: The first 10 lines are output. file Name of the input file. If more than one file is named, the files will be processed in the order in which they are listed, and the output of each file begins with: ==>file<==. Format 2 head[Ë-number][Ëfile] -number Number of lines to be output. number must be a positive decimal number. -nËnumber not specified: The first 10 lines are output. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 file Name of the input file. If more than one file is named, the files will be processed in the order in which they are listed, and the output of each file begins with: ==>file<==. Locale The following environment variables affect the execution of head: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files). U22794-J-Z125-6-76 423 head LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Example Determine the location of message catalogs for the processing of LC_MESSAGES. To see the first 5 lines of three files, you enter the head command as shown below: $ head -5 file1 file2 file3 The first five lines of each of the three files are written to standard output as follows: ==>file1<== Lines 1-5 of file 1 ==>file2<== Lines 1-5 of file 2 ==>file3<== Lines 1-5 of file 3 See also 424 cat, more, tail U22794-J-Z125-6-76 iconv code set conversion iconv reads input characters from a file or from standard input, converts the encoding of these characters, and writes the results on the standard output. The conversions that can be performed with iconv are defined in conversion tables located in the directory /usr/lib/iconv. 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc iconv iconv is typically used to convert characters from the ISO 8859-1 character set to an ISO 646 ASCII variant codeset for a particular language and vice versa (see Examples on page 426). BS2000 You can use iconv for code conversions between ISO646 and EDF03, that is to say between ASCII 7-bit code and EBCDIC. Syntax iconvË-fËfromcodeË-tËtocode[Ëfile] -fËfromcode -tËtocode iconv expects the conversion table to be in the file /usr/lib/iconv/fromcode.tocode.t. Any character that does not exist in the target codeset is converted to an underscore ’_’. file Name of the file for which codeset conversion is to be performed. file not specified: iconv reads from standard input. Not supported xx to yy iconv does not support the requested conversion from codeset xx to target codeset yy. File /usr/lib/iconv Directory containing the standard conversion tables for codeset conversion Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Error /usr/lib/iconv/iconv_data Auxiliary file for iconv /usr/lib/iconv/*.t Conversion tables Locale The following environment variables affect the execution of iconv: LANG U22794-J-Z125-6-76 Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. 425 iconv LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). During translation of the file, this variable is superseded by the use of the fromcode option-argument. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 List all conversion tables: $ ls /usr/lib/iconv 646.edf03.t 646da.8859.t 646de.8859.t 646en.8859.t 646es.8859.t 646fr.8859.t 646it.8859.t 646sv.8859.t 8859.646.t 8859.646da.t 8859.646de.t 8859.646en.t 8859.646es.t 8859.646fr.t 8859.646it.t 8859.646sv.t 8859.edf04.t edf03.646.t edf04.8859.t iconv_data Example 2 Convert the file named letter and save the result in a file named letter.conv. The conversion is to be made from the German variant of the ISO 646 codeset (ASCII derivative) to the target codeset ISO 8859-1: $ iconv -f 646de -t 8859 letter > letter.conv Example 3 You want to convert the contents of the file bs2000 from ASCII to EBCDIC and write the result to the file bs2000.conv: $ iconv -f 646 -t edf03 bs2000 > bs2000.conv 426 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc id id return user identity id writes the following on the standard output for the invoking process: – the user ID (UID) – the login name – the group ID (GID) – the group name. If the effective and real IDs/names are not identical, both are printed. Syntax Format 1: id[Ë-a][Ëuser] Format 2: id[Ë-G][Ë-n][Ëuser] Format 3: id[Ë-g][Ë-nr][Ëuser] Format 4: id[Ë-u][Ë-nr][Ëuser] Format 1 id[Ë-a][Ëuser] -a (all) In addition to the ID and login name of the user, id reports all the groups to which the invoking process belongs and all the groups to which the invoking user belongs. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 user Login name for which the information is output. If user is specified and the process possesses the relevant access permission then the user ID and group ID of the selected user are output. In this case it is assumed that the effective and real IDs are identical. If the database lists more than one permitted group assignment for the user then these assignments are also output. user not specified If the user operand is not specified then id outputs the user and group IDs together with the corresponding login name and group name of the caling process at the standard output. Format 2 id[Ë-G][Ë-n][Ëuser] -G Only the various group IDs (effective, real and supplementary) are output in the format "%u\n". If more than one group assignment is present then all group assignments are output in the format "%u" before the newline character. -n Outputs the name in the format "%s" instead of the format "%u". user see format 1 U22794-J-Z125-6-76 427 id Format 3 id[Ë-g][Ë-nr][Ëuser] -g Only the effective group ID is output. -n Outputs the name as a string. -r Only the real ID is output. user see format 1 Format 4 id[Ë-u][Ë-nr][Ëuser] -u Only the effective user ID is output. -n Outputs the name as a string. -r Only the real ID is output. user see format 1 File /etc/group Group file containing group names and the associated group IDs and login names. Locale The following environment variables affect the execution of id: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH 428 Determine the location of message catalogs for the processing of LC_MESSAGES. U22794-J-Z125-6-76 Example To check your current user ID, group ID, and their corresponding names, you enter: $ id id might then report the following: uid=227(USER1) gid=100(USROTHER) groups=100(USROTHER) See also logname, newgrp, who, getuid() [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc id U22794-J-Z125-6-76 429 info info online diagnostic tool info outputs POSIX subsystem characteristics during a POSIX session. In addition to general information relating to the status of the subsystem it supplies selected items of process information relating to the POSIX users in varying degrees of detail. Ordinary POSIX users are shown information on the general status of the POSIX subsystem (option -s), on the POSIX control parameters (option -t) and on their own processes. The POSIX administrator can also view information on any user process running on the system. Syntax infoË-d|Ë-h|Ë-s|Ë-t|Ë-p[Ë-f][Ë-uËuser][Ë-gËgid][Ë-pËpid] -d Produces a dump for the POSIX subsystem -h Displays help -p Concise information on all POSIX user processes -s General information on the status of the POSIX subsystem -t Lists the POSIX control parameters (see the manual “Basics for Users and System Administrators” [1]) -pf Full information on all POSIX user processes -pË-uËuser Concise information on all processes belonging to user. user may be a login name or a user ID number (UID). -pË-gËgid Concise information on all processes with the group ID number gid. -pfË-uËuser Full information on all processes belonging to user. user may be a login name or a user ID number (UID). -pfË-gËgid Full information on all processes with the group ID number gid. -pË-pËpid Detailed information on the process with the process ID number pid. 430 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc info Example 1 A POSIX user requesting information about the POSIX subsystem: $ info -s GLOBAL SYSTEM INFORMATION: init-TSN: 38YK System status: System is activ ! Rootfsname: :POSX:$SYSROOT.FS.ROOT Number of POSIX users (without 'init' and 'info'): TU users : 6 TPR users : 0 Connected tasks : 6 $ Example 2 The POSIX administrator requesting information about POSIX user processes: # info -p PROCESSINFORMATION GENERAL: PID 18989 1 16 23 9059 18001 7050 PPID 1 0 1 1 9043 16 7039 TU/TPR TU-Task TU-Task -------------------------- TSN 8RJZ 38YK 8RJ5 8RKC 5YQU 9VKQ 5W3F SYSCALL 3 0 87 3 54 87 3 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 USERNAME ROOT ROOT ROOT ROOT ROOT ROOT VSX0 : # U22794-J-Z125-6-76 431 ipcrm ipcrm remove inter-process communication facilities The command ipcrm can be used to remove one or more semaphores, message queues, shared memory or inter-process communication facilities (IPC facilities) from the system. These can be specified either by their identifiers or by the key with which each such IPC facility was created. The identifiers and keys of IPC facilities can be listed with the help of the ipcs command (ID and KEY output columns). For more information on how a message queue, shared memory or semaphore is removed, refer to the msgctl(), shmctl() and semctl() functions in the manual “C Library Functions (BS2000/OSD)” [4]. Syntax ipcrm[Ëoption]... option -qËmsgqid (queue) Removes the message queue identified as msgqid from the system and destroys the data structures associated with it. msgqid Identifier of the message queue to be removed. This identifier is displayed by the ipcs command in the ID column. -QËmsgkey (queue) Removes the message queue identifier msgkey from the system and destroys the data structures associated with it. msgkey Key of the message queue to be removed. This key is displayed by the ipcs command in the KEY column. -mËshmid (memory) Removes the shared memory identified as shmid from the system and destroys the data structures associated with it. shmid Identifier of the shared semaphore set to be removed. This identifier is displayed by the ipcs command in the ID column. -MËshmkey (memory) Removes the shared memory identified as shmkey from the system and destroys the data structures associated with it. shmkey Key with which the shared memory to be removed was created. This key is displayed by the ipcs command in the KEY column. 432 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc ipcrm -sËsemid (semaphore) Removes the semaphore set identified as semid from the system and destroys the data structures associated with it. 7. Juli 2009 Stand 11:58.30 semid Identifier of the semaphore set to be removed. This identifier is displayed by the ipcs command in the ID column. -SËsemkey (semaphore) Removes the semaphore set identified as semkey from the system and destroys the data structures associated with it. semkey Key with which the semaphore set to be removed was created. This key is displayed by the ipcs command in the KEY column. Example Use ipcs to first print a report on the status of the inter-process communication facilities and then remove the message queue with the identifier 40 from the system: $ ipcs IPC status from /dev/kmem as of Mon Mar 9 08:40:41 2009 T ID KEY MODE OWNER GROUP Message Queues: q 40 0x0000004b -Rrw-rw-rw- user1 usrother Shared Memory: Semaphores: $ ipcrm -q 40 ipcs msgctl(), msgget(), semctl(), semget(), semop(), shmctl(), shmget() [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 433 ipcs ipcs inter-process communication status ipcs prints information about active inter-process communication facilities (IPC facilities). You can specify options to control – the type of IPC facilities for which information is to be displayed – what information is to be shown. Since the states of IPC facilities may change while ipcs is running, the displayed information is only current at the time of the request. Syntax ipcs[Ëoption]... No option specified ipcs prints information in short format for – message queues – shared memory – semaphores that are currently active in the system. The meanings of individual output columns are described in the section “Output” on page 436. option There are options for defining the type of IPC facility and options for defining the type of information. Defining the type of IPC facility -q (message queues) Prints information about active message queues. -m (memory) Prints information about active shared memory. -s (semaphores) Prints information about active semaphores. If the -q, -m or -s option is set, only information about the corresponding IPC facility is shown. Any combination of these options is possible. If none of the options are specified, information on all types of IPC facilities will be displayed. 434 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc ipcs Defining the type of information The following section describes the options that select the type of information to be provided for the IPC facilities specified by the -q, -m and -s options. See the “Output” on page 436 for the meaning of the individual output columns. -a (all) Sets all options that print various types of information. This is a shorthand notation for -b, -c, -o, -p and -t. -b (biggest) Prints the biggest allowable size for each respective IPC facility: – For message queues: the maximum number of bytes in a message to be placed on the queue. – For shared memory: the size of the memory segments. – For semaphores: the number of semaphores in each set of semaphores. -c (creator) Prints the user ID (login name) and group name of the creator of the IPC facility. -o (outstanding) Prints information on outstanding IPC facilities, including: – the number of messages on queue – the total number of bytes in messages on queue – the number of processes attached to a shared memory segment. -p (process) Prints process number information, including: – the process ID of the last process that sent a message – the process ID of the last process that received a message – the process ID of the process that created a shared memory segment – the process ID of the last process that used a shared memory segment (attach, detach). Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -t (time) Prints time information. The time of the last control operation that changed the access permissions for all IPC facilities is displayed: – For message queues: time when the system call msgrcv() [4] (receive message from queue) or msgsnd() [4] (send message to queue) was last used. – For shared memory: time when the system call shmat() [4] or shmdt() [4] was last used. – For semaphores: time when the system call semop() [4] was last used on a semaphore. U22794-J-Z125-6-76 435 ipcs Output The column headings and the meanings of the columns in an ipcs listing are given below. The letters in parentheses (...) indicate the options which cause the corresponding heading to appear. all means that the heading always appears. CBYTES (a,o) The number of bytes in messages currently outstanding on the associated message queue. CGROUP (a,c) The group name to which the creator of the IPC facility belongs. CREATOR (a,c) The user ID (login name) of the creator of the IPC facility entry. CTIME (a,t) The time when the associated entry was created or changed. GROUP (all) The group name of the group to which the owner of the IPC facility belongs. ID (all) The identifier for the IPC facility. KEY (all) The key used as an argument when creating the IPC facility with msgget() (create message queue) or semget() (create semaphore set). LRPID (a,p) The process ID of the last process to receive a message from the associated queue. LSPID (a,p) The process ID of the last process to send a message to the associated queue. MODE (all) The IPC facility access modes and status indicators. The mode consists of 11 characters that are interpreted as follows: The first character is: S if a process is waiting on a msgsnd() D if the shared memory segment in question was detached. The character disappears when the shared memory segment is detached by the last process that was attached to it. - if a process is not waiting on a msgsnd(). 436 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.30 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoi.doc ipcs The second character is: R if a process is waiting on a msgrcv() C if the shared memory segment is cleared on executing the first attach. - if a process is not waiting on a msgrcv(). The next 9 characters are interpreted as three sets of three bits each: – The first set refers to the access permissions of the owner of the IPC facility. – The second set represents the access permissions of others belonging to the same user group as the owner of the IPC facility entry. – The third group refers to the access permissions of all other users. Within each set, the first character indicates permission to read, the second character indicates permission to write or alter the IPC facility entry, and the last character is currently unused. The permissions are specified as follows: r w a - if read permission is granted if write permission is granted if permission to alter the IPC facility entry is granted if the indicated permission is not granted. NSEMS (a,b) The number of semaphores in the associated semaphore set. OTIME (a,t) The time the last semaphore operation was completed on the associated semaphore set. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 OWNER (all) The user ID (login name) of the owner of the IPC facility entry. QBYTES (a,b) The maximum number of bytes allowed in messages outstanding on the associated message queue. QNUM (a,o) The number of messages currently outstanding on the associated message queue. RTIME (a,t) The time the last message was received from the associated message queue. STIME (a,t) The time the last message was sent to the associated message queue. NATTCH (a,o) The number of processes attached to the shared memory segment involved. SEGSZ (a,b) The size of the shared memory segment involved. U22794-J-Z125-6-76 437 ipcs CPID (a,p) The process ID of the process that created the shared memory segment. LPID (a,p) The process ID of the last process that used a shared memory segment (attach, detach). ATIME (a,t) The time at which the last attach on the shared memory segment involved was completed. DTIME (a,t) The time at which the last detach on a shared memory segment was completed. T (all) Type of IPC facility: q stands for message queue m stands for shared memory s stands for semaphore. File /etc/group The /etc/group file contains a list of all created group names. Example The server program sets up a message queue. You first start this program in the background and then check the status of the inter-process communication facilities with ipcs: $ server & $ ipcs IPC status from /dev/kmem as of Mon Mar 09 08:40:41 2009 T ID KEY MODE OWNER GROUP Message Queues: q 40 0x0000004b -Rrw-rw-rw- user1 usrother Shared Memory: Semaphores: See also 438 ipcrm msgctl(), msgget(), semctl(), semget(), semop(), shmctl() [4] U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoj.doc Built-in sh command jobs jobs display status of jobs in the current session jobs writes to the standard output. It provides information about the specified jobs or, if job-id is missing, all active jobs. You should only use this command if you have used rlogin to access the POSIX shell. Syntax jobs[Ë-l|p][Ë-n][Ëjob-id]... -l Lists process IDs in addition to the normal information. -p Lists only the process group. -n Lists only the jobs which have already been completed. job-id Information about the specified jobs is output. The section jobs in the chapter "Entering commands from the POSIX shell" contains a description of the format of job-id. job-id not specified: Information about all active jobs is output. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Locale The following environment variables affect the execution of jobs: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Exit status 0 if execution is successful >0 if an error occurs See also bg, fg, kill, wait U22794-J-Z125-6-76 439 join join relational database operator join compares two files on the basis of relations ("join fields") and joins all pairs of lines with identical join fields. The result is displayed on the standard output. When join is invoked, a join field on which the files are to be compared must be specified for each of the two files. Each field is bounded by a pair of field separators. join compares each line in the first file with lines in the second and displays one output line on the standard output for each pair of lines with identical join fields. The output line comprises specific fields from both lines. i Syntax Before the call: Each input file must be sorted so that the join fields are arranged in the currently valid collating sequence (see sort). If the default field separator is used (join without the -t option), leading separators must be ignored (see sort (page 688) option -b) when the files are sorted. However, if you invoke join with option -t, leading field separators must be taken into account when sorting the files (see sort (page 688) without option -b). Format 1: join[Ë-aËn|Ë-vËn][Ë-eËstring][Ë-oËlist][Ë-tËc][Ë-1Ëfield][Ë-2Ëfield] Ëfile1Ëfile2 Format 2: join[Ë-aËn][Ë-eËstring][Ë-jËfield][Ë-j1Ëfield][Ë-j2Ë field][Ë-oËlist...][Ë-tËc] Ëfile1Ëfile2 The formats are described together since the option -jËfield in format 2 corresponds to the options -1Ëfield -2Ë field in format 1. -j1Ëfield is equivalent to -1Ëfield and -j2Ë field is equivalent to -2Ë field. No option specified The first field in a line is the default join field for both files; the default separators are blanks, tabs, and newline characters. Multiple field separators count as one field separator, and leading separators are ignored. join displays one output line on the standard output for each pair of lines with identical join fields. Each output line consists of the following entries in the given order: – the common field – the rest of the line from the first file – the rest of the line from the second file The default output field separator is a blank. 440 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoj.doc join option -aËn (additional output) in addition to the normal output, join outputs all the lines of the nth input file whose comparison field does not match any comparison field in the other file. You may enter 1 or 2 for n. If you require output for both files enter -aË1 -aË2. Option -a and option -v must not both be specified. -vËn Instead of the standard output, a line is generated for each line in n for which no match is found. n may be 1 or 2. If you enter both -vË1 and -vË2 then all the lines for which there is no match are output. -eËstring (empty output fields) Replaces empty output fields with the specified string. -j[n]Ëm The mth field is specified as the comparison field for the nth file. You may enter 1 or 2 for n; m must be a whole number greater than or equal to 1. If you do not specify the option -j for the other file then the comparison field for this other file is the 1st field. n not specified: The join field for both files is the m-th field. -j not specified: The join field for both files is the first field. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -oËlist (output format)join changes the output line format, so that each output line comprises the individual fields specified in list. The common field is not printed unless you explicitly specify it in list. The list you specify must consist of elements in the form n.m, where n is either 1 or 2, and m is greater than or equal to 1. Each element in the form n.m stands for the mth field in the nth file. Individual elements must be delimited by blanks or tabs. -tËc Defines character c as a field separator for both input and output lines. Each occurrence of c is interpreted as a field separator, i.e. – two consecutive c separators designate an empty field, and – a leading c is significant and designates an empty first field. In addition, the newline character acts as a field separator for the input lines. The default field separators (blanks and tabs) are interpreted as field separators only if you specify them as a value for c. U22794-J-Z125-6-76 441 join -1Ëfield Joins the field field from file 1. The fields are decimal whole numbers starting with 1. -2Ëfield Joins the field field from file 2. The fields are decimal whole numbers starting with 1. file1 file2 Names of the two files to be joined on the basis of common fields by join. If you use a dash (-) as the name for file1, join reads from standard input. i Locale If the files are not sorted on their join fields, join will not process all lines! Problems may arise if a numeric file name (e.g. 1.2) is specified for file1 and the -o option is used immediately before this file name is listed. To avoid such conflicts, a numeric file name should be preceded by a slash (e.g. ./1.2). The following environment variables affect the execution of join: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_COLLATE Determine the locale for the collating sequence join expects to have been used when the input files were sorted. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 In the file place, a place is assigned to a name. In the file amount, an amount and a date are assigned to the same names. Both files are sorted by name. join is to join the two files on the names: Contents of place: Albert Buffalo Hugh Washington Irene Philadelphia 442 U22794-J-Z125-6-76 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdoj.doc join Contents of amount: Albert Hugh Hugh Irene Irene 287.56 23.15 167.87 1212.12 1.98 20.03.94 25.06.93 16.12.93 12.12.94 01.01.94 7. Juli 2009 Stand 11:58.31 Join the two files on the first join field: $ join place amount Albert Buffalo 287.56 20.03.94 Hugh Washington 23.15 25.06.93 Hugh Washington 167.87 16.12.93 Irene Philadelphia 1212.12 12.12.94 Irene Philadelphia 1.98 01.01.94 Join the two files and format in columns with awk: $ join place amount | awk '{printf("%-10s %-15s %-10s %-10s\n",$1,$2,$3,$4)}' Albert Buffalo 287.56 20.03.94 Hugh Washington 23.15 25.06.93 Hugh Washington 167.87 16.12.93 Irene Philadelphia 1212.12 12.12.94 Irene Philadelphia 1.98 01.01.94 Example 2 In the file city, a name is assigned to a city. In the file amount (see Example 1), an amount and a date are assigned to a name. city is sorted by cities, amount by names. join is to join the two files on the names. Contents of city: Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Buffalo Buffalo Washington New York Philadelphia Albert Frank Hugh Eric Irene In this example, the join field for city is field 2, while that of amount is field 1. Before the files are joined, city must be sorted on field 2. The output is subsequently formatted into columns with awk: $ sort -b +1 city | join -j1 2 - amount | \ > awk '{printf("%-10s %-15s %-10s %-10s\n",$1,$2,$3,$4)}' Albert Buffalo 287.56 20.03.94 Hugh Washington 23.15 25.06.93 Hugh Washington 167.87 16.12.93 Irene Philadelphia 1212.12 12.12.94 Irene Philadelphia 1.98 01.01.94 See also awk, comm, sort, uniq U22794-J-Z125-6-76 443 kill kill Built-in sh command terminate or signal processes The kill command sends the specified signal to a set of processes indicated by a process number (PID). The ps command can be used to find the process number of any process to which you want to send a signal. Syntax Format 1: kill[Ë-signal]ËpidË... Format 2: killË-sËsignalËpidË... Format 3: killË-signalË-pgidË... Format 4: killË-lË[exit-status] Format 1 Send signals to processes kill[Ë-signal]ËpidË... -signal Signal to be sent to the processes. This signal can be given in the form of a number or a symbolic name. The symbolic signal name is the name as it appears in the header file , without the SIG prefix. A list of these names can be printed with the -l option. Any signal defined in the header file may be specified. The signals below are significant on command level: Signal no. Symb. name Meaning 1 SIGHUP Halt if the user hangs up 2 SIGINT Interrupt via [DEL] 3 SIGQUIT Quit 9 SIGKILL Kill, terminate process unconditionally 15 SIGTERM Software termination, terminate process gracefully The symbolic name 0 which represents the signal value zero is also recognized. signal not specified: kill sends the signal SIGTERM (15) to the specified processes. This will normally kill processes that do not catch or ignore the signal. 444 U22794-J-Z125-6-76 25. Juni 2009 Stand 14:36.34 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdok.doc Built-in sh command kill pid Number (ID) of the process to which a signal is to be sent. Users can only send signals to their own processes. The POSIX administrator can send signals to all processes. Current process IDs can be listed with the ps command. A pid value of 0 has a special meaning: the signal is sent to all processes in your process group. Format 2 Send signals to processes killË-sËsignalËpidË... -sËsignal Signal to be sent to the processes. This signal can be given in the form of a number or a symbolic name. The symbolic signal name is the name as it appears in the header file , without the SIG prefix. A list of these names can be printed with the -l option. Format 3 Send signals to process groups killË-signalË-pgidË... -signal Signal to be sent to the processes of a process group. This signal can be given in the form of a number or a symbolic name. The symbolic signal name is the name as it appears in the header file , without the SIG prefix. A list of these names can be printed with the -l option. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 -pgid The signal is sent to all processes with process group ID pgid. Users can only send signals to their own processes. The POSIX administrator can send signals to all processes. If you specify a value of 1 for pgid, the designated signal will be sent to every process whose real user ID matches the effective user ID of the kill command. As privileged user you send the signal to all processes, with the exception of a number of system processes. U22794-J-Z125-6-76 445 kill Format 4 Built-in sh command List symbolic signal names killË-lË[exit-status] -l A list of all symbolic signal names is printed. exit-status Signal number or exit status of a process which is terminated by a signal. Error no such process You specified an invalid value for pid. no such process group You specified an invalid value for pgid. File Header file in which the symbolic names of signals are defined. Locale The following environment variables affect the execution of kill: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. Example 1 The signal SIGKILL (9) is used to terminate process number 312: $ kill -9 446 312 U22794-J-Z125-6-76 kill Example 2 The following example outputs the status of a terminated job: job stat=$? if [ $stat -eq 0 ] then echo job completed successfully. elif [ $stat -gt 128 ] then echo job terminated by signal SIG$(kill -l $stat). else echo job terminated with error code $stat. fi 25. Juni 2009 Stand 14:36.34 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdok.doc Built-in sh command In order to prevent the possibility that either a signal number or a process group may be specified in the presence of a start argument which contains a negative number and thereby cause an ambiguity, ISO POSIX-2 DIS requires that the former case is always assumed. Therefore if the default signal is to be sent to a process group (e.g. 123), the application must use a command which resembles the following: kill -TERM -123 kill -- -123 ps, trap kill(), signal() [4] Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 See also U22794-J-Z125-6-76 447 let let Built-in sh command integer arithmetic The built-in shell command let provides integer arithmetic. Calculations are performed using long arithmetic. Constants are represented in the form [base#]n where base is an integer between 2 and 36 which specifies the base and n is a number accompanying this base. If base is not specified, calculations are performed in base ten. Syntax Format 1: letËargumentË... Format 2: ((argument))Ë... Format 1 letËargument argument Each argument is an arithmetic expression. The results obtained on evaluation are output. Format 2 ((argument)) Since many of the arithmetic operators must be quoted for the POSIX shell, an alternative form of the let command is provided. For any command which begins with a double left parenthesis ((, all the characters until a matching double right parenthesis )) are treated as a quoted expression. Thus ((a=a+b)) is equivalent to let "a=a+b". Arithmetic evaluation An arithmetic expression uses much the same syntax, precedence, and associativity as the C language. All the integral operators, other than ++, --, ?:, and the comma are supported. Variables can be referenced by name within an arithmetic expression without using the parameter substitution syntax (the $ character). When a variable is referenced, its value is evaluated as an arithmetic expression. An internal integer representation of a variable can be specified as an attribute with the -i option of the built-in typeset command. Arithmetic evaluation is performed on the value of each assignment to a variable with the -i attribute. If you do not specify an arithmetic base, the first assignment to the variable determines the arithmetic base. This base is used when parameter substitution is performed. Exit status 0, if the value of the last expression was not equal to 0 1 otherwise. Error sh: : bad number Incorrect expression 448 U22794-J-Z125-6-76 Example let The following example illustrates a simple arithmetic operation. Both let notations are used. $ let var=10 $ echo $var 10 $ ((var=var-3)) $ echo $var 7 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdol.doc Built-in sh command U22794-J-Z125-6-76 449 lex lex generate programs for lexical tasks lex generates a C program from a file which contains the "lex source text" which you have developed for the problem in hand. A lex source text consists of a maximum of three sections: Definitions, rules and user functions. The rules specify the patterns which are searched for in an input text and the action which is taken if a pattern is found. The definitions and user functions are optional. lex generates a file with the name lex.yy.c. If lex.yy.c is compiled and linked with the Lex library, it copies the input to the output unless a pattern specified in the file is found. In this case the corresponding program text is executed. The pattern which has been matched is located in yytext[], an external character field. Checking and matching of the input file is performed for the search patterns in sequence. Syntax lex[Ë-ctvnV][Ë-Q[y|n]][Ëfile ...] options -c represents the use of C responses and is the default -t the program is written to the file lex.yy.c, not to the standard output -v provides a two line statistical summary -n prevents the printout of the summary generated by -v -V outputs version information at the standard error output -Q[y|n] determines whether or not version information is to be output to the output file lex.yy.c. y|n stands for a yes/no argument in whatever language environment is set. In an English-language environment you enter -Qy to have version information written to lex.yy.c and -Qn to suppress the version information. In a German-language environment, for example, you would use -Qj or -Qn (for ja or nein). By default, no version information is output. file Input file. Multiple files are treated as a single file. file not specified If no file is specified the standard input is used. Some standard table sizes are too small for some users.The table sizes for the automatons which are finally generated can be set in the definition section: %p n Number of positions is n (default 2500) %n n Number of statuses (default 500) %e n Number of nodes on syntax tree is n (1000) %a n Number of transitions is n (2000) %k n Number of packed character classes is n (2500) %o n Size of output field is n (3000) 450 U22794-J-Z125-6-76 Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdol.doc lex The use of one or more sizes automatically entails the option -v if the option -n is not used. The rules section of file starts with the delimiter %%. In the rules section you can define local variables for yylex(). In the rules section, all lines which start with a space or a tab and precede the first rule are copied to the start of the function yylex() directly after the first lefthand parenthesis. Each rule consists of a regular expression which describes a pattern which is to be located and actions which are to be performed if the pattern is found. Input text which corresponds to no search pattern is passed on unchanged to the input file by lex. A regular expression consists of text characters with or without additional operators. The following operators can be used with lex \x x "xy" xy, even if x and/or y are lex operators (except \) [xy] x or y [x-z] x, y or z [^x] any character except x . any character except newline character ^x x at line start x x if lex is in start status y x$ x at line end x? x once or not at all x* empty string or multiple occurrences of x x+ one or more occurrences of x x{m,n} m to n occurrences of x xx|yy xx or yy x | the action of x is also the action for the next rule (x) x x/y x if y follows {xx} substitution for xx from definition section Special tasks can be performed in the action section of a rule. To this end, lex provides the following macros: input() unput() output() U22794-J-Z125-6-76 another character is read from the input stream a character is deferred for a later read process a character is written to the output stream 451 lex You can redefine these macros yourself if you want to control input/output yourself. In this case, ensure that consistency is maintained. Apart from the storage of detected patterns in yytext[] there are other ways of processing detected text patterns using lex functions: yymore() Newly recognized characters are appended to those which are already present in yytext[] (yytext[] is normally overwritten with the next character to be found). yyless(n) Only the first n characters in yytext[] are considered. REJECT Strings which overlap or which are partially contained in other strings are processed. REJECT jumps directly to the next rule without modifying the contents of yytext[]. Hint If a lex program is linked with c89 [5], then -ll must be specified as the archive parameter. Locale The following environment variables affect the execution of lex: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding default value from the internationalized environment is used. If any of the internationalisation variables contains an invalid setting, the command behaves as if none of the variables have been defined. LC_ALL If set to a non-empty value, override the values of all the other internationalisation variables. LC_COLLATE Determine the locale for the behavior of ranges, equivalence classes and multicharacter collating elements within regular expressions. If this variable is not set to the POSIX locale, the results are unspecified. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (e.g. single-byte characters as opposed to multi-byte characters in arguments and input files), and the behavior of character classes within regular expressions. If this variable is set to the POSIX locale, the results are unspecified. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. See also 452 yacc U22794-J-Z125-6-76 ln ln link files ln creates links to existing files or directories. This allows you to access these files and/or directories under various file names or path names (see Functionality). To make a link with ln, you need write permission for the directory in which the link is to be entered. 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdol.doc Built-in sh command There are two types of link: Syntax – Hard link: When you create a hard link to a file, there are multiple directory entries for this file, either in one directory or in different directories, but the physical file is only present once. The inode for each file contains a link counter which is decremented by one when a link is removed. The file itself is not deleted until all links to it have been removed. A hard link cannot be used to refer to a directory or to files on different file systems. – Symbolic link: A symbolic link is a file that contains a path name. When the shell encounters a file name that represents a symbolic link, it replaces this name with the specified path name. Thus what you access is not the symbolic link, but the file to which the path name points. You can set up symbolic links to any files or directories, even to those on different file systems. Format 1: ln[Ëoption]ËsourceËtarget Format 2: ln[Ëoption]ËsourceË...Ëtargdir Format 3: lnË-sËsourceËtarget Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 Format 4: lnË-sËsourceË...Ëtargdir Format 1 Make a hard link ln[Ëoption]ËsourceËtarget ln makes a new link named target to the file named source. The file can then be accessed under both names, i.e. source and target. No option specified If there is already a file with the same name as the new link and you do not have write permission for it, ln will display its access permissions and ask you to confirm whether or not the link should be made. The link will not be created unless your answer begins with y (see and target (page 454) and Example 2 on page 460). ! U22794-J-Z125-6-76 Caution! If the standard input is not a terminal, no confirmation is requested and the link is not made. 453 ln Built-in sh command option -f (force) If a file named target already exists, ln creates the link without asking questions, regardless of whether or not you have write permission for the file. -n If a file named target already exists, its contents are not overwritten. The -f option overrides this option. source Name of the file to which you want to make a link. The file must already exist when you call ln. You are not allowed to specify a directory as the source. target Name of the link that you wish to make to source. target can be a simple file name (basename) or an absolute or relative path name: a basename: ln enters the basename target in the current working directory. an absolute or relative path name in the form prefix/name: ln enters the basename name in the directory identified as prefix. If there is already a file named target and you have write permission for it, ln creates the link without asking questions. In other words, the name target now references source, and not the file originally called target; and if target was the only link to (i.e. name of) the original file, the contents of the original file are deleted. If you do not have write permission for the original target, ln asks you if you really want it to make the link (see option -f and Example 2 on page 460). If the parent directory of target is writable but has the sticky bit set, one of the following conditions must be fulfilled in order to for target to be created: – the file must be owned by the user – the directory must be owned by the user – the user must have write permission for the file – the user must be a privileged user. This format of ln cannot be used to create links that span different file systems. Such links can be made using the -s option (see Format 3 on page 456 and Format 4 on page 456). 454 U22794-J-Z125-6-76 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdol.doc Built-in sh command Format 2 ln Make a hard link with the same name in another directory ln[Ëoption]ËsourceË...Ëtargdir ln creates a link to the file (or files) named source in another directory named targdir. The file can then be accessed in two different directories under the same basic file name (basename). No option specified If there is already a file with the same name as the new link to be created, and if you do not have write permission for it, ln will display its access permissions and ask you to confirm whether or not the link should be made. The link will not be created unless your answer begins with y. ! Caution! If the standard input is not a terminal, no confirmation is requested and no link is created. option -f (force) If targdir already contains a file named source, ln creates the link without asking questions, regardless of whether or not you have write permission for it. -n If a file named source already exists in targdir, its contents are not overwritten. The -f option overrides this option. Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 source Name of the file to which you want to make a link. The file must already exist when you call ln. You are not allowed to make links to directories. You can name any number of files in one call. The specified source can be a file basename or an absolute or relative path name: a basename: ln enters the basename source in the named targdir. an absolute or relative path name in the form prefix/name: ln enters the basename name in the named targdir. If there is already a file with the basename source in targdir and you have write permission for it, ln creates the link without asking questions. In other words, the link now references source, and not the file in targdir originally called source; and if source was the only link to (i.e. name of) the original file, the contents of the original file are deleted. If you do not have write permission for the original file in targdir, ln asks you if you really want it to make the link (see option -f and Example 2 on page 460). targdir Name of the directory in which the link is to be entered. The directory must already exist. This format of ln cannot be used to create links that span different file systems. U22794-J-Z125-6-76 455 ln Format 3 Built-in sh command Make a symbolic link lnË-sËsourceËtarget ln -s makes a symbolic link named target to the named source, where source can be a file or a directory. The main difference with ln -s is that it creates symbolic links, which can span different file systems. This is not possible with hard links. source Name of the file or directory to which a symbolic link is to be made. source may be specified as any path name and need not exist. It may also reside on a different file system from target. target Name of the symbolic link that you wish to make to source. target can be a file basename or an absolute or relative path name: a basename: ln enters the basename target as a symbolic link in the current working directory. an absolute or relative path name in the form prefix/name: ln enters the basename name in the directory identified as prefix. If a file named target already exists, an error message is returned (see page 458). The existing file is not overwritten. Format 4 Make a symbolic link with the same name in another directory lnË-sËsourceË...Ëtargdir For each file or directory that is specified as source, ln creates a symbolic link in the directory targdir. These links can span different file systems. source Name of the file or directory to which you want to make a symbolic link. You can name any number of sources in one call. The specified source can be an absolute or relative path name: an absolute or relative path name in the form prefix/name: ln enters the basename name in the directory targdir as a symbolic link to prefix/name. If targdir already contains a file with the same basename as name, an error is returned (see page 458), and the existing file is not overwritten. targdir Name of the directory in which the symbolic links are to be created. This directory must exist. 456 U22794-J-Z125-6-76 ln Functionality ● Hard links When ln makes a link to a file, the basic file name (basename) associated with the link is entered in the appropriate directory. This entry receives the same inode number as the original file name. Thus, both file names have the same inode, and consequently the same attributes (access permissions, owner, dates, etc.). The physical file referenced by the file names is only present once, but the user can now access the same file under different file or path names (see Example 1 on page 459). 7. Juli 2009 Stand 11:58.31 Pfad: G:\fsc\posix\A41\e\Kommandos\posutil_e.v04\kdol.doc Built-in sh command The inode number indicates whether two file names are linked to the same file (see ls -i on page 481); the number of links shows you how many directory entries exist for the file (see ls -l on page 481). The rm command can be used to remove an entry (link) from a directory. If there was more than one link to the file, it can still be accessed under the remaining names. rm does not delete the file itself until the last link (i.e. name) is removed. ● Symbolic links Dokuschablonen 19x24 Version 7.31us für FrameMaker V7.x vom 07.03.2007 © cognitas GmbH 2001-2007 A symbolic link is a file that contains a path name. These path names can be listed with the command ls -l. When the shell encounters a file name that represents a symbolic link, it replaces this name with the specified path name. In other words, one path name is mapped to another. There is no link counting mechanism in this case; when a symbolic link is removed, the file containing the path name is deleted. The inode of the physical file that is referenced by a symbolic link does not contain any information about the link. The link counter only keeps track of hard links. This means that if you delete the target of a symbolic link, the link will continue to exist, but will now refer to a file having no contents and no inode. Symbolic links are not restricted by file system boundaries, and the path names contained in them may refer both to files and to directories. Symbolic links can be shown with the ls command: – ls -l indicates which files in the specified directory are symbolic links. The contents of each symbolic link, i.e. the path name of the referenced file, are shown following the file name and the symbol ’->’. – ls -L provides information on the file or directory that is referenced by the symbolic link. Operations involving ‘..’ (such as ‘cd ..’) in a directory that is symbolically linked will reference the original directory, not the target. U22794-J-Z125-6-76 457 ln Error Built-in sh command ln: Cannot link
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.6 Linearized : Yes Page Mode : UseOutlines XMP Toolkit : 3.1-702 Producer : Acrobat Distiller 7.0.5 (Windows) Copyright : Fujitsu Technology Solutions GmbH, 2009 Create Date : 2009:07:07 11:50:35Z Creator Tool : FrameMaker 7.1 Modify Date : 2009:07:07 16:24:12+02:00 Metadata Date : 2009:07:07 16:24:12+02:00 Format : application/pdf Title : POSIX - Commands Creator : cognitas GmbH on behalf of Fujitsu Technology Solutions GmbH Description : Commands Document ID : uuid:e2b986ad-5ca1-4620-87fa-c7e3d3f9192b Instance ID : uuid:390bddb4-7e7a-4452-8880-cea2200135f8 Page Count : 918 Subject : Commands Author : cognitas GmbH on behalf of Fujitsu Technology Solutions GmbHEXIF Metadata provided by EXIF.tools