logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

fc.1p (15879B)


  1. '\" et
  2. .TH FC "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. fc
  12. \(em process the command history list
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. fc \fB[\fR-r\fB] [\fR-e \fIeditor\fB] [\fIfirst \fB[\fIlast\fB]]\fR
  17. .P
  18. fc -l\fB [\fR-nr\fB] [\fIfirst \fB[\fIlast\fB]]\fR
  19. .P
  20. fc -s\fB [\fIold\fR=\fInew\fB] [\fIfirst\fB]\fR
  21. .fi
  22. .SH DESCRIPTION
  23. The
  24. .IR fc
  25. utility shall list, or shall edit and re-execute, commands previously
  26. entered to an interactive
  27. .IR sh .
  28. .P
  29. The command history list shall reference commands by number. The first
  30. number in the list is selected arbitrarily. The relationship of a
  31. number to its command shall not change except when the user logs in and
  32. no other process is accessing the list, at which time the system may
  33. reset the numbering to start the oldest retained command at another
  34. number (usually 1). When the number reaches an
  35. implementation-defined upper limit, which shall be no smaller than
  36. the value in
  37. .IR HISTSIZE
  38. or 32\|767 (whichever is greater), the shell may wrap the numbers,
  39. starting the next command with a lower number (usually 1). However,
  40. despite this optional wrapping of numbers,
  41. .IR fc
  42. shall maintain the time-ordering sequence of the commands. For
  43. example, if four commands in sequence are given the numbers 32\|766,
  44. 32\|767, 1 (wrapped), and 2 as they are executed, command 32\|767 is
  45. considered the command previous to 1, even though its number is
  46. higher.
  47. .P
  48. When commands are edited (when the
  49. .BR \-l
  50. option is not specified), the resulting lines shall be entered at the
  51. end of the history list and then re-executed by
  52. .IR sh .
  53. The
  54. .IR fc
  55. command that caused the editing shall not be entered into the history
  56. list. If the editor returns a non-zero exit status, this shall
  57. suppress the entry into the history list and the command re-execution.
  58. Any command line variable assignments or redirection operators used
  59. with
  60. .IR fc
  61. shall affect both the
  62. .IR fc
  63. command itself as well as the command that results; for example:
  64. .sp
  65. .RS 4
  66. .nf
  67. fc -s -- -1 2>/dev/null
  68. .fi
  69. .P
  70. .RE
  71. .P
  72. reinvokes the previous command, suppressing standard error for both
  73. .IR fc
  74. and the previous command.
  75. .SH OPTIONS
  76. The
  77. .IR fc
  78. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  79. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  80. .P
  81. The following options shall be supported:
  82. .IP "\fB\-e\ \fIeditor\fR" 10
  83. Use the editor named by
  84. .IR editor
  85. to edit the commands. The
  86. .IR editor
  87. string is a utility name, subject to search via the
  88. .IR PATH
  89. variable (see the Base Definitions volume of POSIX.1\(hy2017,
  90. .IR "Chapter 8" ", " "Environment Variables").
  91. The value in the
  92. .IR FCEDIT
  93. variable shall be used as a default when
  94. .BR \-e
  95. is not specified. If
  96. .IR FCEDIT
  97. is null or unset,
  98. .IR ed
  99. shall be used as the editor.
  100. .IP "\fB\-l\fP" 10
  101. (The letter ell.) List the commands rather than invoking an editor on
  102. them. The commands shall be written in the sequence indicated by the
  103. .IR first
  104. and
  105. .IR last
  106. operands, as affected by
  107. .BR \-r ,
  108. with each command preceded by the command number.
  109. .IP "\fB\-n\fP" 10
  110. Suppress command numbers when listing with
  111. .BR \-l .
  112. .IP "\fB\-r\fP" 10
  113. Reverse the order of the commands listed (with
  114. .BR \-l )
  115. or edited (with neither
  116. .BR \-l
  117. nor
  118. .BR \-s ).
  119. .IP "\fB\-s\fP" 10
  120. Re-execute the command without invoking an editor.
  121. .SH OPERANDS
  122. The following operands shall be supported:
  123. .IP "\fIfirst\fR,\ \fIlast\fR" 10
  124. Select the commands to list or edit. The number of previous commands
  125. that can be accessed shall be determined by the value of the
  126. .IR HISTSIZE
  127. variable. The value of
  128. .IR first
  129. or
  130. .IR last
  131. or both shall be one of the following:
  132. .RS 10
  133. .IP "\fB[+]\fInumber\fR" 10
  134. A positive number representing a command number; command numbers can be
  135. displayed with the
  136. .BR \-l
  137. option.
  138. .IP "\fB\-\fInumber\fR" 10
  139. A negative decimal number representing the command that was executed
  140. .IR number
  141. of commands previously. For example, \-1 is the immediately previous
  142. command.
  143. .IP "\fIstring\fR" 10
  144. A string indicating the most recently entered command that begins with
  145. that string. If the
  146. .IR old =\c
  147. .IR new
  148. operand is not also specified with
  149. .BR \-s ,
  150. the string form of the
  151. .IR first
  152. operand cannot contain an embedded
  153. <equals-sign>.
  154. .P
  155. When the synopsis form with
  156. .BR \-s
  157. is used:
  158. .IP " *" 4
  159. If
  160. .IR first
  161. is omitted, the previous command shall be used.
  162. .P
  163. For the synopsis forms without
  164. .BR \-s :
  165. .IP " *" 4
  166. If
  167. .IR last
  168. is omitted,
  169. .IR last
  170. shall default to the previous command when
  171. .BR \-l
  172. is specified; otherwise, it shall default to
  173. .IR first .
  174. .IP " *" 4
  175. If
  176. .IR first
  177. and
  178. .IR last
  179. are both omitted, the previous 16 commands shall be listed or the
  180. previous single command shall be edited (based on the
  181. .BR \-l
  182. option).
  183. .IP " *" 4
  184. If
  185. .IR first
  186. and
  187. .IR last
  188. are both present, all of the commands from
  189. .IR first
  190. to
  191. .IR last
  192. shall be edited (without
  193. .BR \-l )
  194. or listed (with
  195. .BR \-l ).
  196. Editing multiple commands shall be accomplished by presenting to the
  197. editor all of the commands at one time, each command starting on a new
  198. line. If
  199. .IR first
  200. represents a newer command than
  201. .IR last ,
  202. the commands shall be listed or edited in reverse sequence, equivalent
  203. to using
  204. .BR \-r .
  205. For example, the following commands on the first line are equivalent to
  206. the corresponding commands on the second:
  207. .RS 4
  208. .sp
  209. .RS 4
  210. .nf
  211. fc -r 10 20 fc 30 40
  212. fc 20 10 fc -r 40 30
  213. .fi
  214. .P
  215. .RE
  216. .RE
  217. .IP " *" 4
  218. When a range of commands is used, it shall not be an error to specify
  219. .IR first
  220. or
  221. .IR last
  222. values that are not in the history list;
  223. .IR fc
  224. shall substitute the value representing the oldest or newest command in
  225. the list, as appropriate. For example, if there are only ten commands
  226. in the history list, numbered 1 to 10:
  227. .RS 4
  228. .sp
  229. .RS 4
  230. .nf
  231. fc -l
  232. fc 1 99
  233. .fi
  234. .P
  235. .RE
  236. .P
  237. shall list and edit, respectively, all ten commands.
  238. .RE
  239. .RE
  240. .IP "\fIold\fP=\fInew\fR" 10
  241. Replace the first occurrence of string
  242. .IR old
  243. in the commands to be re-executed by the string
  244. .IR new .
  245. .SH STDIN
  246. Not used.
  247. .SH "INPUT FILES"
  248. None.
  249. .SH "ENVIRONMENT VARIABLES"
  250. The following environment variables shall affect the execution of
  251. .IR fc :
  252. .IP "\fIFCEDIT\fP" 10
  253. This variable, when expanded by the shell, shall determine the default
  254. value for the
  255. .BR \-e
  256. .IR editor
  257. option's
  258. .IR editor
  259. option-argument. If
  260. .IR FCEDIT
  261. is null or unset,
  262. .IR ed
  263. shall be used as the editor.
  264. .IP "\fIHISTFILE\fP" 10
  265. Determine a pathname naming a command history file. If the
  266. .IR HISTFILE
  267. variable is not set, the shell may attempt to access or create a file
  268. .BR .sh_history
  269. in the directory referred to by the
  270. .IR HOME
  271. environment variable. If the shell cannot obtain both read and write
  272. access to, or create, the history file, it shall use an unspecified
  273. mechanism that allows the history to operate properly. (References to
  274. history ``file'' in this section shall be understood to mean this
  275. unspecified mechanism in such cases.) An implementation may choose to
  276. access this variable only when initializing the history file; this
  277. initialization shall occur when
  278. .IR fc
  279. or
  280. .IR sh
  281. first attempt to retrieve entries from, or add entries to, the file, as
  282. the result of commands issued by the user, the file named by the
  283. .IR ENV
  284. variable, or implementation-defined system start-up files. In some
  285. historical shells, the history file is initialized just after the
  286. .IR ENV
  287. file has been processed. Therefore, it is implementation-defined
  288. whether changes made to
  289. .IR HISTFILE
  290. after the history file has been initialized are effective.
  291. Implementations may choose to disable the history list mechanism for
  292. users with appropriate privileges who do not set
  293. .IR HISTFILE ;
  294. the specific circumstances under which this occurs are
  295. implementation-defined. If more than one instance of the shell is
  296. using the same history file, it is unspecified how updates to the
  297. history file from those shells interact. As entries are deleted from
  298. the history file, they shall be deleted oldest first. It is
  299. unspecified when history file entries are physically removed from the
  300. history file.
  301. .IP "\fIHISTSIZE\fP" 10
  302. Determine a decimal number representing the limit to the number of
  303. previous commands that are accessible. If this variable is unset, an
  304. unspecified default greater than or equal to 128 shall be used. The
  305. maximum number of commands in the history list is unspecified, but
  306. shall be at least 128. An implementation may choose to access this
  307. variable only when initializing the history file, as described under
  308. .IR HISTFILE .
  309. Therefore, it is unspecified whether changes made to
  310. .IR HISTSIZE
  311. after the history file has been initialized are effective.
  312. .IP "\fILANG\fP" 10
  313. Provide a default value for the internationalization variables that are
  314. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  315. .IR "Section 8.2" ", " "Internationalization Variables"
  316. for the precedence of internationalization variables used to determine
  317. the values of locale categories.)
  318. .IP "\fILC_ALL\fP" 10
  319. If set to a non-empty string value, override the values of all the
  320. other internationalization variables.
  321. .IP "\fILC_CTYPE\fP" 10
  322. Determine the locale for the interpretation of sequences of bytes of
  323. text data as characters (for example, single-byte as opposed to
  324. multi-byte characters in arguments and input files).
  325. .IP "\fILC_MESSAGES\fP" 10
  326. .br
  327. Determine the locale that should be used to affect the format and
  328. contents of diagnostic messages written to standard error.
  329. .IP "\fINLSPATH\fP" 10
  330. Determine the location of message catalogs for the processing of
  331. .IR LC_MESSAGES .
  332. .SH "ASYNCHRONOUS EVENTS"
  333. Default.
  334. .SH STDOUT
  335. When the
  336. .BR \-l
  337. option is used to list commands, the format of each command in the list
  338. shall be as follows:
  339. .sp
  340. .RS 4
  341. .nf
  342. "%d\et%s\en", <\fIline number\fR>, <\fIcommand\fR>
  343. .fi
  344. .P
  345. .RE
  346. .P
  347. If both the
  348. .BR \-l
  349. and
  350. .BR \-n
  351. options are specified, the format of each command shall be:
  352. .sp
  353. .RS 4
  354. .nf
  355. "\et%s\en", <\fIcommand\fR>
  356. .fi
  357. .P
  358. .RE
  359. .P
  360. If the <\fIcommand\fP> consists of more than one line, the lines after
  361. the first shall be displayed as:
  362. .sp
  363. .RS 4
  364. .nf
  365. "\et%s\en", <\fIcontinued-command\fR>
  366. .fi
  367. .P
  368. .RE
  369. .SH STDERR
  370. The standard error shall be used only for diagnostic messages.
  371. .SH "OUTPUT FILES"
  372. None.
  373. .SH "EXTENDED DESCRIPTION"
  374. None.
  375. .SH "EXIT STATUS"
  376. The following exit values shall be returned:
  377. .IP "\00" 6
  378. Successful completion of the listing.
  379. .IP >0 6
  380. An error occurred.
  381. .P
  382. Otherwise, the exit status shall be that of the commands executed by
  383. .IR fc .
  384. .SH "CONSEQUENCES OF ERRORS"
  385. Default.
  386. .LP
  387. .IR "The following sections are informative."
  388. .SH "APPLICATION USAGE"
  389. Since editors sometimes use file descriptors as integral parts of their
  390. editing, redirecting their file descriptors as part of the
  391. .IR fc
  392. command can produce unexpected results. For example, if
  393. .IR vi
  394. is the
  395. .IR FCEDIT
  396. editor, the command:
  397. .sp
  398. .RS 4
  399. .nf
  400. fc -s | more
  401. .fi
  402. .P
  403. .RE
  404. .P
  405. does not work correctly on many systems.
  406. .P
  407. Users on windowing systems may want to have separate history files for
  408. each window by setting
  409. .IR HISTFILE
  410. as follows:
  411. .sp
  412. .RS 4
  413. .nf
  414. HISTFILE=$HOME/.sh_hist$$
  415. .fi
  416. .P
  417. .RE
  418. .SH "EXAMPLES"
  419. None.
  420. .SH RATIONALE
  421. This utility is based on the
  422. .IR fc
  423. built-in of the KornShell.
  424. .P
  425. An early proposal specified the
  426. .BR \-e
  427. option as
  428. .BR [\-e
  429. .IR editor
  430. .BR [ \c
  431. .IR old \c
  432. =
  433. .IR new
  434. .BR ]\|] ,
  435. which is not historical practice. Historical practice in
  436. .IR fc
  437. of either
  438. .BR [\-e
  439. .IR editor \c
  440. .BR ]
  441. or
  442. .BR "[\-e \- ["
  443. .IR old \c
  444. =
  445. .IR new
  446. .BR ]\|]
  447. is acceptable, but not both together. To clarify this, a new option
  448. .BR \-s
  449. was introduced replacing the
  450. .BR "[\-e \-]" .
  451. This resolves the conflict and makes
  452. .IR fc
  453. conform to the Utility Syntax Guidelines.
  454. .IP "\fIHISTFILE\fP" 10
  455. Some implementations of the KornShell check for the superuser
  456. and do not create a history file unless
  457. .IR HISTFILE
  458. is set. This is done primarily to avoid creating unlinked files in the
  459. root file system when logging in during single-user mode.
  460. .IR HISTFILE
  461. must be set for the superuser to have history.
  462. .IP "\fIHISTSIZE\fP" 10
  463. Needed to limit the size of history files. It is the intent of the
  464. standard developers that when two shells share the same history file,
  465. commands that are entered in one shell shall be accessible by the other
  466. shell. Because of the difficulties of synchronization over a network,
  467. the exact nature of the interaction is unspecified.
  468. .P
  469. The initialization process for the history file can be dependent on the
  470. system start-up files, in that they may contain commands that
  471. effectively preempt the settings the user has for
  472. .IR HISTFILE
  473. and
  474. .IR HISTSIZE .
  475. For example, function definition commands are recorded in the history
  476. file. If the system administrator includes function definitions in some
  477. system start-up file called before the
  478. .IR ENV
  479. file, the history file is initialized before the user can influence its
  480. characteristics. In some historical shells, the history file is
  481. initialized just after the
  482. .IR ENV
  483. file has been processed. Because of these situations, the text requires
  484. the initialization process to be implementation-defined.
  485. .P
  486. Consideration was given to omitting the
  487. .IR fc
  488. utility in favor of the command line editing feature in
  489. .IR sh .
  490. For example, in
  491. .IR vi
  492. editing mode, typing
  493. .BR \(dq<ESC> v\(dq
  494. is equivalent to:
  495. .sp
  496. .RS 4
  497. .nf
  498. EDITOR=vi fc
  499. .fi
  500. .P
  501. .RE
  502. .P
  503. However, the
  504. .IR fc
  505. utility allows the user the flexibility to edit multiple commands
  506. simultaneously (such as
  507. .IR fc
  508. 10 20) and to use editors other than those supported by
  509. .IR sh
  510. for command line editing.
  511. .P
  512. In the KornShell, the alias
  513. .BR r
  514. (``re-do'') is preset to
  515. .IR fc
  516. .BR "\-e \-"
  517. (equivalent to the POSIX
  518. .IR fc
  519. .BR \-s ).
  520. This is probably an easier command name to remember than
  521. .IR fc
  522. (``fix command''), but it does not meet the Utility Syntax Guidelines.
  523. Renaming
  524. .IR fc
  525. to
  526. .IR hist
  527. or
  528. .IR redo
  529. was considered, but since this description closely matches historical
  530. KornShell practice already, such a renaming was seen as gratuitous.
  531. Users are free to create aliases whenever odd historical names such as
  532. .IR fc ,
  533. .IR awk ,
  534. .IR cat ,
  535. .IR grep ,
  536. or
  537. .IR yacc
  538. are standardized by POSIX.
  539. .P
  540. Command numbers have no ordering effects; they are like serial numbers.
  541. The
  542. .BR \-r
  543. option and \-\fInumber\fP operand address the sequence of command
  544. execution, regardless of serial numbers. So, for example, if the
  545. command number wrapped back to 1 at some arbitrary point, there would
  546. be no ambiguity associated with traversing the wrap point. For example,
  547. if the command history were:
  548. .sp
  549. .RS 4
  550. .nf
  551. 32766: echo 1
  552. 32767: echo 2
  553. 1: echo 3
  554. .fi
  555. .P
  556. .RE
  557. .P
  558. the number \-2 refers to command 32\|767 because it is the second
  559. previous command, regardless of serial number.
  560. .SH "FUTURE DIRECTIONS"
  561. None.
  562. .SH "SEE ALSO"
  563. .IR "\fIsh\fR\^"
  564. .P
  565. The Base Definitions volume of POSIX.1\(hy2017,
  566. .IR "Chapter 8" ", " "Environment Variables",
  567. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  568. .\"
  569. .SH COPYRIGHT
  570. Portions of this text are reprinted and reproduced in electronic form
  571. from IEEE Std 1003.1-2017, Standard for Information Technology
  572. -- Portable Operating System Interface (POSIX), The Open Group Base
  573. Specifications Issue 7, 2018 Edition,
  574. Copyright (C) 2018 by the Institute of
  575. Electrical and Electronics Engineers, Inc and The Open Group.
  576. In the event of any discrepancy between this version and the original IEEE and
  577. The Open Group Standard, the original IEEE and The Open Group Standard
  578. is the referee document. The original Standard can be obtained online at
  579. http://www.opengroup.org/unix/online.html .
  580. .PP
  581. Any typographical or formatting errors that appear
  582. in this page are most likely
  583. to have been introduced during the conversion of the source files to
  584. man page format. To report such errors, see
  585. https://www.kernel.org/doc/man-pages/reporting_bugs.html .