iPXE discussion forum
Whitespace in strings - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: Whitespace in strings (/showthread.php?tid=8145)



Whitespace in strings - weaver6999 - 2016-07-29 22:17

How does one go about printing whitespace characters with echo? I'm attempting to center some text and since there is no option to do so with echo (possible feature enhancement?), I figured I'd try some equivalent methods. Escape sequences don't seem to work: [2J successfully clears the screen, but [12C seems to be interpreted (single blank space in output) and then ignored (no movement to the right). 'echo' with blank spaces and then the string only prints the string. 'echo' with quotes around blank spaces and string appears to print the quote, a space, and then the string, with all other leading spaces stripped. I suppose I could do 12x 'echo -n', but is there an easier/better way of doing this?


RE: Whitespace in strings - NiKiZe - 2016-08-02 20:31

you can use ${} ${} to get a space.
the feature here is that double spaces is automatically trimmed, sometimes that might not be what you want and in those cases you can use the empty settings trick above.

other then that based on the clear screen example in http://ipxe.org/cmd/set#examples
Code:
set sp:hex 20:20:20:20:20
set sp ${sp:string}
# show 1 followed by 5 spaces and then 5
echo 1${sp}5



RE: Whitespace in strings - weaver6999 - 2016-08-03 08:26

(2016-08-02 20:31)NiKiZe Wrote:  
Code:
set sp:hex 20:20:20:20:20
set sp ${sp:string}
# show 1 followed by 5 spaces and then 5
echo 1${sp}5

Oooooo, quite clever, I like it. I think that will work well enough for my needs. Awesome answer!