Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"lsblk -P -f" output cannot be parsed by shell #1201

Closed
magic-david opened this issue Nov 25, 2020 · 3 comments
Closed

"lsblk -P -f" output cannot be parsed by shell #1201

magic-david opened this issue Nov 25, 2020 · 3 comments

Comments

@magic-david
Copy link

Given:

lsblk -P /dev/disk/by-id/google-persistent-disk-1 -f

Output is:

NAME="sdb" FSTYPE="ext4" LABEL="" UUID="060038ea-ba10-462e-99ec-79a0f8b2f0e1" FSAVAIL="" FSUSE%="" MOUNTPOINT=""

Given:

eval $( lsblk -P /dev/disk/by-id/google-persistent-disk-1 -f )

Error is:

FSUSE%=: command not found

Suggest removing the % from the variable name. Will send patch later if I have some free time

@karelzak
Copy link
Collaborator

karelzak commented Dec 2, 2020

Good point, it seems we have the same thing in lsipc and findmnt.

The question if we need to care about it as there is always non-% variant of the number and you should not blindly use defaults (like -P) in your scripts as it is subject to change (as described in the man page).

Now when I think about it then the column rename is a backwardly incompatible change, let's imagine you have

 FOO=$(lsblk -nro FSUSE% /dev/sda1)

in your script. I think we should not touch the name, maybe improve the way how libsmartcols prints the variable name for -P:

https://github.com/karelzak/util-linux/blob/master/libsmartcols/src/print.c#L474-L479

maybe remove % (and other bad chars) in from variable name or use some escape for %, or so.

@magic-david
Copy link
Author

Maybe a search-replace for % -> PCT? Sucky I know

karelzak added a commit that referenced this issue Dec 3, 2020
The shells are very restrictive about variable names, only [:alnum:]
chars are allowed (and alphabetic chars as the first char).  The
library will replace "bad" chars with "_". The char '%' at the end is
replaced by _PCT.

Addresses: #1201
Signed-off-by: Karel Zak <kzak@redhat.com>
@karelzak
Copy link
Collaborator

karelzak commented Dec 3, 2020

Fixed. Note that we had an issue also with many variables (column names) like MIN-IO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants