]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add -y/--shell
authorKarel Zak <kzak@redhat.com>
Fri, 11 Feb 2022 11:37:48 +0000 (12:37 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 11 Feb 2022 11:37:48 +0000 (12:37 +0100)
Fixes: https://github.com/util-linux/util-linux/issues/1594
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.8.adoc
misc-utils/lsblk.c

index 7568f2a7e00d65a43aff5af63b0dae3e9e7c0929..ceae7078adee54bc53fb7840dce9c35cb2c0d2a0 100644 (file)
@@ -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<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%.
+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<code>). 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.
 
index e382f8df43c776e6b9e9c8fa87987450a21d85dd..4a0d372899eb7977c5bbed8338346d7e0a6d9763 100644 (file)
@@ -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 <num>    specifies output width as number of characters\n"), out);
        fputs(_(" -x, --sort <column>  sort output by <column>\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 <dir>  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));