just starting out BASH and Linux in general. I've been struggling to add spaces for this variable and it'll be great help if someone could guide me here.

I tried this and didn't work"

$ line2="        "AppID": {"

This is the desired output that has several spaces starting notice the spaces in the beginning

Thank you. Prakash

  • Welcome to Unix & Linux! Please don't post images of text. Instead, copy/paste the text into your question and use the formatting tools to format it as code.
    – terdon
    Jun 6, 2022 at 14:32
  • It does work. I am guessing you forgot to quote the variable when you tested: try again, but use echo "$line2". Isn't that what you want?
    – terdon
    Jun 6, 2022 at 14:33
  • perfect!! thank you terdon Jun 6, 2022 at 14:39
  • You're welcome. I will mark this as a duplicate of our main post explaining the importance of quoting shell variables.
    – terdon
    Jun 6, 2022 at 14:47
  • If you want to generalize, if you have a list of identifiers such as extendedProperties or AppID, you could have an awk function to print the length of each of the items in that list, the pipe to sort, uniq then take the largest value and pass it to a second awk function for formatting, which would use -v indent="${maxLenght}", then when you print those identifiers, use the printf("%"indent"s {\n", $0 ) to format your output. Sep 14, 2022 at 2:38


Browse other questions tagged .