Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
In my version of ksh (pdksh), echo is a builtin, and it knows about "-n":
Producing:
There is a long passage in man ksh about special, regular, etc., commands, comparing the original ksh to the POSIX version. Perhaps that is causing the apparent anomaly -- I readily admit that using pdksh is not proof of anything in ksh.
I generally go by the guideline that less is better: "echo" is shorter than "print" , although there are cases when printf is very useful.
Actually, I have never seen any version of ksh that does not have a version of echo built in. Dave Korn intended that the builtin echo would mirror the behavior of the external command echo on any OS. He provided the print command so that portable ksh scripts could be written. Then came Posix which standardized the echo command. Posix does not recognize print but does recognize printf. printf tends to not be a builtin among the various versions of ksh. The print command supports the -u option and you can't use co-processes without it. Personally I use echo and expect a Posix compliant echo. And I use print when echo won't do. Because printf tends to be an external command, I resist it, but it is very powerful and, sometimes, it is worth the cost.
In AIX, the ksh88 "echo" is a builtin and uses "\c" but not "-n". Same for ksh93, and same for /bin/echo.
On MacOSX, ksh rules are reversed (uses "-n" but not "\c"). However, /bin/echo will happily accept either form.
It looks like you need to balance your portability needs against the speed/elegance of code. Apparently the ony way to be sure of cross-platform success is to use printf, which is an external program. (You could also use perl, or awk, but...gads.)
The echo builtins and /bin/echo should be equivilant, although they are not always!
Stupid POSIX. A laudable goal but it sure seems to dumb things down. When can we go to POSIX 2.0?
Please explain why this works. Am unable to find another definition for the '%', which would explain this behaviour:
spaceLeft=`df -h /myPartition | tail -1`
# output looks like: /dev/sda5 10G 1.2G 12G 29% /
set -- $space
#this deletes the trailing '%' sign, which is... (6 Replies)
#!/usr/bin/ksh
var1="Hi World"
var2="Morning"
var3=$(echo "$var1" \n "$var2")
echo $var3
var3=$(printf "$var1 \n $var2")
echo $var3
Output
Any way to get
in my $var3 ? (7 Replies)
Hello All
Nice to meet you all here in this forum,
it's my 1rst time here
i'm asking about a little issue that i face
i added a ksh script that echo " please insert your name " and store the output to a login.log file.
the script is working fine with normal telnet
but Xstart is not working... (8 Replies)
Hello,
I have lib file which contain a function that get text to print on screen by echo command.
Several scripts are inculde this lib and use this function.
Each one of them is written in different shell language (sh ksh & bash).
This causing some issues when using backslash charater as... (4 Replies)
Hi all,
I was to echo Hi in Red and Bold ; and echo There is in Green and bold
I got bold to working using tput bold but i am having hard time getting the color.
Any help is appreciated,
jak (4 Replies)
Probably my first post, very new to shell scripting :)
Here is the script i am trying to modify to use function
# Script to create simple menus and take action according to that selected
# menu item
#
while :
do
clear
echo "-------------------------------------"
echo "... (2 Replies)
Hi folks,
I need to stop printing a new line after echoing a string in KSH. i know bash provides
echo -n "string"
what is the ksh equivalent for this ? (3 Replies)
hi, this echo $SHELL will give the shell name.. how to get the other list of variables (besides SHELL) values?
and also, different shells have different variable names (example SHELL) (10 Replies)