From: Karel Zak Date: Fri, 11 Feb 2022 11:37:48 +0000 (+0100) Subject: lsblk: add -y/--shell X-Git-Tag: v2.38-rc2~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25fb0638ad7bba588b902717b97ad03863b2e710;p=thirdparty%2Futil-linux.git lsblk: add -y/--shell Fixes: https://github.com/util-linux/util-linux/issues/1594 Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk.8.adoc b/misc-utils/lsblk.8.adoc index 7568f2a7e0..ceae7078ad 100644 --- a/misc-utils/lsblk.8.adoc +++ b/misc-utils/lsblk.8.adoc @@ -84,7 +84,7 @@ The default list of columns may be extended if _list_ is specified in the format Output all available columns. *-P*, *--pairs*:: -Produce output in the form of key="value" pairs. The output lines are still ordered by dependencies. All potentially unsafe value characters are hex-escaped (\x). 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%. +Produce output in the form of key="value" pairs. The output lines are still ordered by dependencies. All potentially unsafe value characters are hex-escaped (\x). See also option *--shell*. *-p*, *--paths*:: Print full device paths. @@ -114,6 +114,9 @@ Specifies output width as a number of characters. The default is the number of t *-x*, *--sort* _column_:: Sort output lines by _column_. This option enables *--list* output format by default. It is possible to use the option *--tree* to force tree-like output and than the tree branches are sorted by the _column_. +*-y*, *--shell*:: +The column name will be modified to contain only characters allowed for shell variable identifiers, for example, MIN_IO and FSUSE_PCT instead of MIN-IO and FSUSE%. This is usable, for example, with *--pairs*. Note that this feature has been automatically enabled for *--pairs* in version 2.37, but due to compatibility issues, now it’s necessary to request this behavior by *--shell*. + *-z*, *--zoned*:: Print the zone related information for each device. diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index e382f8df43..4a0d372899 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -139,6 +139,7 @@ enum { LSBLK_EXPORT = (1 << 3), LSBLK_TREE = (1 << 4), LSBLK_JSON = (1 << 5), + LSBLK_SHELLVAR = (1 << 6) }; /* Types used for qsort() and JSON */ @@ -1924,6 +1925,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -t, --topology output info about topology\n"), out); fputs(_(" -w, --width specifies output width as number of characters\n"), out); fputs(_(" -x, --sort sort output by \n"), out); + fputs(_(" -y, --shell modify column names to be usable as shell variable identifiers\n"), out); fputs(_(" -z, --zoned print zone related information\n"), out); fputs(_(" --sysroot use specified directory as system root\n"), out); fputs(USAGE_SEPARATOR, out); @@ -1993,6 +1995,7 @@ int main(int argc, char *argv[]) { "scsi", no_argument, NULL, 'S' }, { "sort", required_argument, NULL, 'x' }, { "sysroot", required_argument, NULL, OPT_SYSROOT }, + { "shell", no_argument, NULL, 'y' }, { "tree", optional_argument, NULL, 'T' }, { "version", no_argument, NULL, 'V' }, { "width", required_argument, NULL, 'w' }, @@ -2023,7 +2026,7 @@ int main(int argc, char *argv[]) lsblk_init_debug(); while((c = getopt_long(argc, argv, - "AabdDzE:e:fhJlnMmo:OpPiI:rstVST::w:x:", + "AabdDzE:e:fhJlnMmo:OpPiI:rstVST::w:x:y", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -2087,6 +2090,9 @@ int main(int argc, char *argv[]) lsblk->flags |= LSBLK_EXPORT; lsblk->flags &= ~LSBLK_TREE; /* disable the default */ break; + case 'y': + lsblk->flags |= LSBLK_SHELLVAR; + break; case 'i': lsblk->flags |= LSBLK_ASCII; break; @@ -2234,6 +2240,7 @@ int main(int argc, char *argv[]) errx(EXIT_FAILURE, _("failed to allocate output table")); scols_table_enable_raw(lsblk->table, !!(lsblk->flags & LSBLK_RAW)); scols_table_enable_export(lsblk->table, !!(lsblk->flags & LSBLK_EXPORT)); + scols_table_enable_shellvar(lsblk->table, !!(lsblk->flags & LSBLK_SHELLVAR)); scols_table_enable_ascii(lsblk->table, !!(lsblk->flags & LSBLK_ASCII)); scols_table_enable_json(lsblk->table, !!(lsblk->flags & LSBLK_JSON)); scols_table_enable_noheadings(lsblk->table, !!(lsblk->flags & LSBLK_NOHEADINGS));