- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need to retain white space in shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 06:04 AM
тАО03-16-2009 06:04 AM
need to retain white space in shell script
I don't want to loose "white space" which is suffix of any string but when i am doing echo, i loose those white spaces. Can anyone help me in this regard? Example
#!/bin/perl
string="123 "
echo "$string"
Output :
123 ## white spaces get removed
required output
123 ##which contains spaces as well.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 07:15 AM
тАО03-16-2009 07:15 AM
Re: need to retain white space in shell script
You may also try using print instead of echo, but both should yield the same result and that is the exact string you input, including spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 10:44 AM
тАО03-16-2009 10:44 AM
Re: need to retain white space in shell script
#!/bin/ksh
string="123 "
echo "$string"
Output is :
123
in above output white-spaces get trimmed automatically.
But Required O/P should be :
123(with white space)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 10:48 AM
тАО03-16-2009 10:48 AM
Re: need to retain white space in shell script
white-space also trimmed in this forum......please consider "dot"(.) as white space and then realize my problem.
Suppose "Dot"as white-space
#!/bin/ksh
string="123....................."
echo "$string"
Output is :
123
in above output white-spaces get trimmed automatically.
But Required O/P should be :
123.......................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 10:56 AM
тАО03-16-2009 10:56 AM
Re: need to retain white space in shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 11:11 AM
тАО03-16-2009 11:11 AM
Re: need to retain white space in shell script
consider "Dot" as white-space
$echo "123......................."
123
$
(above is the o/p of command)
But i want output with "white-spaces" how can i achieve it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-16-2009 11:46 AM
тАО03-16-2009 11:46 AM
Re: need to retain white space in shell script
$ echo '123 1 ' > t.txt
Then open t.txt in an editor like vi. You will see that the trailing spaces are in fact there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2009 05:22 AM
тАО03-25-2009 05:22 AM
Re: need to retain white space in shell script
#!/bin/ksh
string="123 "
string2=" 456"
print "$string$string2"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2009 05:24 AM
тАО03-25-2009 05:24 AM
Re: need to retain white space in shell script
If you use echo "$c" your script should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2009 09:43 PM
тАО04-19-2009 09:43 PM
Re: need to retain white space in shell script
`echo' writes each given STRING to standard output, with a space
between each and a newline after the last one.
So does not matter how many white space you give in echo it would be reduced to one white space between characters , and for only one contunoius string...all white space after character would vanish"
This is what echo do.
If you want to have echo do as said above.
echo "$string"
put $string in quotes.
BR,
Kapil+
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2009 09:45 PM
тАО04-19-2009 09:45 PM
Re: need to retain white space in shell script
[root@rspc521 suraj]# cat o
#!/bin/ksh
string="123 "
echo "$string"
[root@rspc521 suraj]# sh o >oo
[root@rspc521 suraj]# cat oo
123
[root@rspc521 suraj]#
in the above output you can see the output of oo is 123 but if you open file oo and give the command :se list then you can see the space after 123.
Suraj