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>
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.
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
...