}
}
+static inline void fputs_shell_ident(const char *data, FILE *out)
+{
+ const char *p = data;
+
+ /* convert "1FOO" to "_1FOO" */
+ if (p && !isalpha(*p))
+ fputc('_', out);
+
+ /* replace all "bad" chars with "_" */
+ for (p = data; p && *p; p++) {
+ if (!isalnum(*p))
+ fputc('_', out);
+ else
+ fputc(*p, out);
+ }
+}
#endif /* _CAREFULPUTC_H */
return 0;
case SCOLS_FMT_EXPORT:
- fprintf(tb->out, "%s=", name);
+ fputs_shell_ident(name, tb->out);
+ if (endswith(name, "%"))
+ fputs("PCT", tb->out);
+ fputc('=', tb->out);
fputs_quoted(data, tb->out);
if (!is_last)
fputs(colsep(tb), tb->out);
* Enable/disable export output format (COLUMNAME="value" ...).
* The parsable output formats (export and raw) are mutually exclusive.
*
+ * Note that COLUMNAME maybe be modified on output to contains only chars
+ * allowed as shell variable identifiers, for example MIN-IO and FSUSE% will be
+ * MIN_IO and FSUSE_PCT.
+ *
* Returns: 0 on success, negative number in case of an error.
*/
int scols_table_enable_export(struct libscols_table *tb, int enable)
are not included.
.TP
.BR \-P , " \-\-pairs"
-Use key="value" output format. All potentially unsafe characters are hex-escaped (\\x<code>).
+Produce output in the form of key="value" pairs. All potentially unsafe value characters are hex-escaped (\\x<code>).
+The key (variable name) will be modified to contain only characters allowed for a shell variable
+identifiers, for example, FS_OPTIONS and USE_PCT instead of FS-OPTIONS and USE%.
.TP
.BR \-p , " \-\-poll\fR[\fI=list\fR]"
Monitor changes in the /proc/self/mountinfo file. Supported actions are: mount,
.TP
.BR \-P , " \-\-pairs"
Produce output in the form of key="value" pairs. The output lines are still ordered by
-dependencies. All potentially unsafe characters are hex-escaped (\\x<code>).
+dependencies. All potentially unsafe value characters are hex-escaped (\\x<code>).
+The key (variable name) will be modified to contain only characters allowed for a shell variable
+identifiers, for example, MIN_IO and FSUSE_PCT instead of MIN-IO and FSUSE%.
.TP
.BR \-p , " \-\-paths"
Print full device paths.
Show creator and owner.
.TP
\fB\-e\fR, \fB\-\-export\fR
-Output data in the format of NAME=VALUE.
+Produce output in the form of key="value" pairs. All potentially unsafe value
+characters are hex-escaped (\\x<code>). The key (variable name) will be
+modified to contain only characters allowed for a shell variable identifiers,
+for example, USE_PCT instead of USE%.
.TP
\fB\-J\fR, \fB\-\-json\fR
Use the JSON output format.
Output all available columns.
.TP
.BR \-P , " \-\-pairs"
-Produce output in the form of key="value" pairs.
-All potentially unsafe characters are hex-escaped (\\x<code>).
+Produce output in the form of key="value" pairs. All potentially unsafe value
+characters are hex-escaped (\\x<code>).
.TP
.BR \-r , " \-\-raw"
Produce output in raw format. All potentially unsafe characters are hex-escaped