Tiny Core Extensions > TCE Bugs

wbar.tcz bug and fix

<< < (5/6) > >>

Rich:
Hi GNUser

--- Quote from: GNUser on October 30, 2024, 12:08:13 PM ---Hmm, I don't like using trim/echo here. It does more than just get rid of trailing whitespace. ...
--- End quote ---
Quotes can change how variables are treated.
For example:

--- Code: ---tc@E310:~$ Var1="    Too many   spaces    "
tc@E310:~$ echo "$Var1"
    Too many   spaces
tc@E310:~$ echo $Var1
Too many spaces
--- End code ---
With quotes, it's a string. Without quotes, it's a series of fields.
Either way, they all show up.

Here's one that has tripped me up in the past.
This works:

--- Code: ---tc@E310:~$ for W in $Var1; do echo $W; done
Too
many
spaces
--- End code ---

This doesn't:

--- Code: ---tc@E310:~$ for W in "$Var1"; do echo $W; done
Too many spaces
--- End code ---

When you call a function, it looks like this:

--- Code: ---Function Var1 Var2 Var3 ....
--- End code ---

Without quotes, it's treated as Vars separated by whitespace:

--- Code: ---tc@E310:~$ trim $Var1
Too
--- End code ---

If I change this:

--- Code: ---trim() { echo $1; }
--- End code ---
To this:

--- Code: ---trim() { echo $*; }
--- End code ---

It works with or without quotes:

--- Code: ---tc@E310:~$ trim $Var1
Too many spaces
tc@E310:~$ trim "$Var1"
Too many spaces
--- End code ---

mocore:

--- Quote from: gadget42 on October 30, 2024, 04:21:30 AM ---https://unix.stackexchange.com/questions/102008/how-do-i-trim-leading-and-trailing-whitespace-from-each-line-of-some-output

--- End quote ---

fwiw
one answer contains ltrim rtrim and trum  with  sed / shell function
this one https://unix.stackexchange.com/questions/102008/how-do-i-trim-leading-and-trailing-whitespace-from-each-line-of-some-output/660011#660011

Juanito:
Did we come to a conclusion on this?

GNUser:
Hi Juanito. Folks pointed out 1001 ways to fix the problem, many of which are equally good.

I think the patch in Reply #18 is the most straight-forward. Would you like me to use that patch and submit patched wbar.tcz extensions for TCL15 x86 and x86_64?

Rich:
Hi GNUser
Agreed.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version