commit 9475ab261beabd848267f925940c15f9fd6eb96e
parent 7a643120366f1ea24eac5ccb759d4df616e7789b
Author: Toby Goodwin <toby@paccrat.org>
Date: Mon, 19 Mar 2018 21:59:02 +0000
Merge branch 'master' into ifnot
Diffstat:
3 files changed, 44 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -919,3 +919,5 @@ Changes since rc-1.5b2
2018-03-19
Feature: implement `if not`.
+
+ Feature: default values for $nl and $tab (github #43).
diff --git a/main.c b/main.c
@@ -83,11 +83,13 @@ quitopts:
inithash();
initparse();
assigndefault("ifs", " ", "\t", "\n", (void *)0);
+ assigndefault("nl", "\n", (void *)0);
#ifdef DEFAULTPATH
assigndefault("path", DEFAULTPATH, (void *)0);
#endif
assigndefault("pid", nprint("%d", rc_pid), (void *)0);
assigndefault("prompt", "; ", "", (void *)0);
+ assigndefault("tab", "\t", (void *)0);
assigndefault("version",
VERSION,
"$Release: @(#)" PACKAGE " " VERSION " " DESCRIPTION " $",
diff --git a/rc.1 b/rc.1
@@ -1194,14 +1194,15 @@ is used to split the output into list elements.
By default,
.Cr $ifs
has the value space-tab-newline.
+.PP
The braces may be omitted if the command is a single word.
Thus
.Cr \`ls
may be used instead of
.Cr "\`{ls}" .
-This last feature is useful when defining functions that expand
-to useful argument lists.
-A frequent use is:
+This last feature can be used to create shortcuts by defining functions that
+expand to useful argument lists.
+For example:
.Ds
.Cr "fn src { echo *.[chy] }"
.De
@@ -1211,8 +1212,8 @@ followed by
.Cr "wc \`src"
.De
.PP
-(This will print out a word-count of all C source files in the current
-directory.)
+This will print out a word-count of all C source files in the current
+directory.
.PP
In order to override the value of
.Cr $ifs
@@ -1232,10 +1233,31 @@ For example:
.PP
splits up
.Cr /etc/passwd
-into fields, assuming that
+into fields.
+.PP
+As a convenience,
+.I rc
+defines
.Cr $nl
-contains a newline
-as its value.
+to contain the newline character, and
+.Cr $tab
+to contain the tab character. Thus, if you want to process everything in the
+current directory, but in a random order, you could use:
+.Ds
+.Cr "for (f in \`\` $nl {ls | shuf}) { ... process $f }"
+.De
+.PP
+This will correctly handle filenames that contain spaces.
+.PP
+Note that
+.I rc
+scripts that use backquote substitution should avoid relying on the default
+values of
+.Cr $ifs ,
+.Cr $nl ,
+or
+.Cr $tab .
+Instead, they should explicitly set what they need.
.SH "SPECIAL VARIABLES"
Several variables are known to
.I rc
@@ -1387,6 +1409,11 @@ backquote commands for digestion as a list. On startup,
assigns the list containing the characters space, tab, and newline to
.Cr $ifs .
.TP
+.Cr nl " (default)"
+Contains the newline character (see
+.BR "Backquote substitution"
+above).
+.TP
.Cr path " (alias)"
This is a list of directories to search in for commands.
The empty string stands for the current directory.
@@ -1469,6 +1496,11 @@ usually sets
to
.Cr "(0 0)" .
.TP
+.Cr tab " (default)"
+Contains the tab character (see
+.BR "Backquote substitution"
+above).
+.TP
.Cr version " (default)"
On startup, the first element of this list variable is initialized to
a string which identifies this version of