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

Manually setting IFS breaks if resourced #613

Closed
Rycieos opened this issue Jun 30, 2020 · 0 comments
Closed

Manually setting IFS breaks if resourced #613

Rycieos opened this issue Jun 30, 2020 · 0 comments
Labels
bug sensors Related to the use of lm-sensors to get temperature data
Milestone

Comments

@Rycieos
Copy link
Collaborator

Rycieos commented Jun 30, 2020

Shell: bash 4.4.19(1)-release
Operating system: Linux 4.18.0-193.6.3.el8_2.x86_64, CentOS Linux release 8.2.2004 (Core)
Liquidprompt version: v1.12-beta.1

Steps to Reproduce

  1. Load Liquidprompt like normal.
  2. Run IFS="" and/or unset IFS.
  3. Source Liquidprompt again (. liquidprompt).

Expected Behavior

No errors are printed on each prompt.

Current Behavior

Every prompt return prints something like this:

-bash: 6
16
5: syntax error in expression (error token is "16
5")
-bash: local: 4 0.13 0.10 1/924 69756/4: syntax error in expression (error token is "0.13 0.10 1/924 69756/4")

Turning on debug traces like this:

++++ _lp_temp_sensors
++++ local -i i
+++++ sensors -u
+++++ sed -n 's/^  temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'
++++ for i in $(sensors -u |
                sed -n 's/^  temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p')
-bash: 6
16
4: syntax error in expression (error token is "16
4")
+++ _lp_sr ''
+++ [[ -n '' ]]
++ LP_TEMP=
++++ _lp_load_color
++++ ((  LP_ENABLE_LOAD  ))
++++ local lp_cpu_load
++++ _lp_cpu_load
++++ local eol
++++ read lp_cpu_load eol
++++ lp_cpu_load='007 0.11 0.09 1/920 64709'
++++ lp_cpu_load='07 0.11 0.09 1/920 64709'
++++ lp_cpu_load='7 0.11 0.09 1/920 64709'
++++ local -i 'load=7 0.11 0.09 1/920 64709/4'
-bash: local: 7 0.11 0.09 1/920 64709/4: syntax error in expression (error token is "0.11 0.09 1/920 64709/4")

Possible Solution

Probably we need to create a local IFS each time we are going to for loop through some program output. Probably local IFS='\n' here would be a start:
https://github.com/nojhan/liquidprompt/blob/5f9bb675c10023ddf578ec1f4c0a79d6a1193ba4/liquidprompt#L1512-L1513

@Rycieos Rycieos added bug sensors Related to the use of lm-sensors to get temperature data labels Jun 30, 2020
@Rycieos Rycieos added this to the v1.12 milestone Jun 30, 2020
@Rycieos Rycieos closed this as completed in 94148e5 Jul 7, 2020
pkkolos pushed a commit to pkkolos/liquidprompt that referenced this issue May 9, 2021
Liquidprompt was relying on the default IFS for most needs. This was
somewhat safe, as it saved the IFS value from startup, and used that
when it needed an IFS value. The problem cropped up when the user set a
blank, weird, or completely unset value for IFS before sourcing
Liquidprompt. In this case some `read` calls would fail.

The simple fix is anywhere IFS is used, to make a local IFS with the
exact value that is needed. There are only two cases that use IFS:
* `read`, which uses IFS to split the string into fields to put into the
  specified variables.
* Unquoted $var or $(command) references, often passed into `for` or
  similar. Note that this doesn't apply to unquoted variable assignments
  (`foo=$bar`, doesn't need to be quoted, will never split).

Fixes liquidprompt#613
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug sensors Related to the use of lm-sensors to get temperature data
Projects
None yet
Development

No branches or pull requests

1 participant