Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:23:33+00:00 2026-06-17T04:23:33+00:00

The new-line character is correctly recognized on server2 (Solaris) while it is taken as

  • 0

The new-line character is correctly recognized on server2 (Solaris) while it is taken as a backslashn character on server1 (Linux). How do I correct this?

While working on a simple script that accepts arguments and sends out mails I first noticed this rather odd behavior..

Syntax: $ ksh SEND_MAIL.sh <to> <Subject> <body>

  1. Now when I run that script on server-1

    [kent@server1] $ ksh SEND_MAIL.sh name@site.com “Subject” “123\n456”
    [Thu Jan 10 10:51:18 EST 2013] – Starting to send mail to: name@site.com,
    with the subject \’>>>123\n456\’

    Notice that the new-line character is taken as backlash-n.

  2. While on server-2 the \n special character correctly expands to a new-line character.

    [kent@server2] $ ksh SEND_MAIL.sh name@site.com “Subject” “123\n456”
    [Thu Jan 10 10:51:18 EST 2013] – Starting to send mail to: name@site.com,
    with the subject \’>>>123
    456\’

I think I may need to change some KornShell environment variables but I can not figure it out.

UPDATE:

After Henk’s guidance below… I see that knowing the difference is not enough in helping me solve main issue – that is to have the script on server1 recognize the \n characters as a new-line. So I have improved my question.


Notes:

Server1 is a Linux server, while Server2 is Solaris.


Environment details > KornShell: – As suggested by Henk Langeveld

On server1:

[kent@server1]$ ksh --version
  version         sh (AT&T Research) 93t+ 2010-02-02
[kent@server1]$ echo ${.sh.version}
bash: ${.sh.version}: bad substitution
[kent@server1]$ [ "${ERRNO}" ] && echo ksh88 || echo ksh93
ksh93
[kent@server1]$ [ "`echo "\c" | grep c`" ] && echo ksh93 || echo ksh88 
ksh93

On server2:

# I'm am in bash
[kent@server2]$ ksh --version 
$
$ ksh --version
$ 
[kent@server2]$ echo ${.sh.version}
bash: ${.sh.version}: bad substitution
[kent@server2]$ [ "${ERRNO}" ] && echo ksh88 || echo ksh93
ksh93
[kent@server2]$ [ "`echo "\c" | grep c`" ] && echo ksh93 || echo ksh88 
ksh93

On server 1 & 2 I get the same behavior:

$ echo -e "1\n2"
1
2
$ echo "1\n2"
1\n2
$ echo $'1\n2'
1
2

Code:

SEND_MAIL.sh

#Syntax: $ ksh SEND_MAIL.sh <to> <Subject> <body>
TO_REC=$1
SUBJECT=$2
MESSAGE=$3
echo "$MESSAGE"| mailx -s "$SUBJECT" $TO_REC

Putting the line set | grep SH in the script on both the servers to check the shell it is running on as Oliver suggested below.

On server1:

[kent@server1]$ ksh SEND_MAIL.sh kent@123.com "Subject" ">>>123\n\n456$a"
KSH_VERSION=.sh.version
SHELL=/bin/bash
SHLVL=3
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_CLIENT='3.209.100.144 59645 22'
SSH_CONNECTION='3.209.100.144 59645 3.56.9.127 22'
SSH_TTY=/dev/pts/1
...

On server2:

[kent@server2]$ ksh SEND_MAIL.sh kent@123.com "Subject" ">123\n\n456$a"
SHELL=/bin/ksh
SHLVL=1
SSH_CLIENT='3.209.100.144 49351 22'
SSH_CONNECTION='3.209.100.144 49351 3.56.29.159 22'
SSH_TTY=/dev/pts/2
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:23:35+00:00Added an answer on June 17, 2026 at 4:23 am

    Is this AST ksh93, pdksh, or an older ksh88?

    Here’s how you can check the version of your ksh by checking the output of ksh --version and the value of ${.sh.version}

    $ ksh --version
    version         sh (AT&T Research) 93u+ 2012-06-26
    $ ksh -c 'echo ${.sh.version}'
    Version AJM 93u+ 2012-06-26
    

    Then tell us if the results are the same on the two servers. Older versions of ksh may actually report an error.


    Solution for ksh93:

    On server1, embed your \n in a ksh93 Ansi string, by enclosing it in $' and ':

    two_lines=$'one\ntwo'  && print "$two_lines"
    one
    two
    

    This will extrapolate any C-style escapes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to prevent the new line character at the beginning of the text entering
Sometimes i would like to search for text containing a new line character and
So evidently: \n = CR (Carriage Return) // Used as a new line character
How do you append a new line(\n\r) character in StringBuilder ?
How do i add a new line characters to html body of mail composer?
My JSON contains special characters like: new line, double quotes etc. I am creating
I am trying to use the New Methods for National Character Set Type Data
I'm using this code to read a line of text from a file :
I'm facing an issue with character encoding in linux. I'm retrieving a content from
Tables in my database are created with a correct UTF-8 charset like this: CREATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.