[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 408
  • Last Modified:

How to write a delimited string with space using shell script?

Hi,

Here is my test script:

#/bin/ksh

....
pp="\"ABC DEF GHI\""
echo $pp
printf "%35s \n" $pp
...

The output is

"ABC DEF GHI"
                               "ABC
                                DEF
                               GHI"

How to I fix the printf statement so that the output is the same as the echo statement?

Thanks
0
tommym121
Asked:
tommym121
  • 2
1 Solution
 
woolmilkporcCommented:
printf "%35s \n" "$pp"
 
 Playing around with "quotes" is always a good idea!
 
 wmp
0
 
woolmilkporcCommented:
OK,

to make the output exactly look the same  use

printf "%-35s \n" "$pp"

(the minus sign - !)
0
 
tommym121Author Commented:
Ah... didn't try this one.

Thank you.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now