The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell and echo replyramdas Shell Programming and Scripting 2 02-27-2008 03:40 AM
run a shell script with echo keerthi UNIX for Advanced & Expert Users 7 06-21-2006 05:38 PM
FTP--How to use echo?? rahul26 UNIX for Advanced & Expert Users 1 06-14-2006 09:47 AM
Echo escaped \c in SH Shell Any Idea asami Shell Programming and Scripting 4 05-04-2006 07:24 AM
echo $SHELL, $PWD and etc. yls177 UNIX for Dummies Questions & Answers 10 12-30-2002 10:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-11-2008
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
Echo with ksh shell

Hi All,
I'm trying to use the "echo" command in a korn shell script, and I want it to drop the trailing newline. Now I know that with the bash shell, the "-n" flag would solve this issue. Does anyone know how this can be done with the korn shell?

Cheers
Khoom
  #2 (permalink)  
Old 01-11-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
From man ksh

Code:
       echo [-neE] [arg ...]
              Prints its arguments (separated by spaces) followed by  a  new-
              line, to standard out.  The newline is suppressed if any of the
              arguments contain the backslash sequence \c.  See print command
              below  for  a list of other backslash sequences that are recog-
              nized.

              The options are  provided  for  compatibility  with  BSD  shell
              scripts:  -n  suppresses the trailing newline, -e enables back-
              slash interpretation (a no-op, since this  is  normally  done),
              and -E which suppresses backslash interpretation.
Did you try with -n ?
  #3 (permalink)  
Old 01-11-2008
Khoomfire Khoomfire is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 68
<Sigh> Vino,

In a ksh script, the line

echo -n "hi I'm happy"


will give the output

-n hi I'm happy
  #4 (permalink)  
Old 01-11-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Code:
[/tmp]$ cat try.ksh
#! /bin/ksh

echo -n "test"
[/tmp]$ ./try.ksh
test[/tmp]$
  #5 (permalink)  
Old 01-11-2008
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
In Korn, a simple option is to use print or printf.

Code:
     print [ -Rnprsu[n ] ] [ arg ... ]

         The shell output mechanism. With no flags or with flag -
         or  -,  the  arguments are printed on standard output as
         described by echo(1). The exit status is 0,  unless  the
         output file is not open for writing.
  #6 (permalink)  
Old 01-11-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
I'd like to second reborg: for the umpteenth time now: if in ksh, use "print" AND NOT "echo"! "print" is a shell-built-in in ksh and therefore preferable over an external command like "echo".

bakunin
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0