You are not logged in.

#1 2015-06-29 16:22:26

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

[solved] Bash leading spaces issue

The problem is simple, but I can find a solution. It's all about leading spaces.

#!/bin/bash

var="    test"
echo $var

# desired output
# >    test

# actual output
# > test

I've tried everything I can think of, quotes, no quotes, escaping, double escaping, end so on, but nothing seems to work and I have yet to find any answers online, though not for lag of trying. Apparently it's not a problem people often have, and I can see why, ut regardsless I need leading spaces, for now at least, so please let me know if you know of a solution.


Best regards.

Last edited by zacariaz (2015-06-29 16:57:36)


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#2 2015-06-29 16:27:51

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,858
Website

Re: [solved] Bash leading spaces issue

You say you tried quotes, but where?

echo "$var"

should work.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2015-06-29 16:28:13

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,525
Website

Re: [solved] Bash leading spaces issue

zacariaz wrote:

I've tried everything I can think of, quotes

Really?

$ var="    test"
$ echo "$var"
    test

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2015-06-29 16:29:38

Scimmia
Fellow
Registered: 2012-09-01
Posts: 11,553

Re: [solved] Bash leading spaces issue

echo "$var"

Offline

#5 2015-06-29 16:57:21

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: [solved] Bash leading spaces issue

Well... That I didn't think of.

Thanks.


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

Board footer

Powered by FluxBB