|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to preserve space while concatenating strings? (KSH)
I have these Code:
str1=$(echo "This is string one with spaces \n This is also my sentence 1") When I echo $str1, it displays the new line character properly. Now I have another new variable say str2. I want to concatenate in this way.. str1 + newline character + and then str2. That's I want the output to be: Code:
This is string one with spaces This is also my sentence 1 Content of str2 How do I do it? I tried Code:
$str1 = "$str1 $(echo "\n") $str2" and Code:
$str1 = "$str1 \n $str2" and Code:
$str1 = "$str1 $(echo $IFS) $str2" None of those works ![]() ---------- Post updated at 12:36 PM ---------- Previous update was at 12:30 PM ---------- If I just say echo $str1 "\n" $str2 at the cmd prompt, it works fine. It does not work when I try to store it in variable... it loses the new line character when stored in a variable. |
| Sponsored Links | |
|
|
|
#3
|
|||
|
|||
|
Code:
# echo -e $str1"\nContent of str2" This is string one with spaces This is also my sentence 1 Content of str2 |
| The Following User Says Thank You to ygemici For This Useful Post: | ||
dahlia84 (07-30-2010) | ||
|
#4
|
|||
|
|||
|
Thanks both of you! It worked I am using something like this now...Code:
s3=$(echo "$s1" "\n" "$s2") echo $s3 |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CSH: Concatenating Strings, how to add new line character and functions? | ragabonds | Shell Programming and Scripting | 0 | 05-04-2009 07:15 PM |
| concatenating strings | tulip | Shell Programming and Scripting | 2 | 02-05-2009 01:59 PM |
| mailx: concatenating strings for message body (KSH) | rockysfr | Shell Programming and Scripting | 1 | 07-29-2007 08:12 AM |
| concatenating strings.. | jt_csv | Shell Programming and Scripting | 2 | 02-07-2007 09:09 PM |
| Concatenating Strings | radhika03 | Shell Programming and Scripting | 2 | 09-09-2005 02:48 AM |
|
|