echo and new line


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users echo and new line
# 1  
Old 12-11-2008
echo and new line

hi

I want to display:

The students are:
a
b
c

What I get from
echo "The students are:" "$list"

is

The students are: a
b
c


any idea?
# 2  
Old 12-11-2008
Quote:
Originally Posted by melanie_pfefer
hi

I want to display:

The students are:
a
b
c

What I get from
echo "The students are:" "$list"

is

The students are: a
b
c


any idea?
try this
Code:
 
 echo "The students are:\n""$list"

# 3  
Old 12-11-2008
Quote:
Originally Posted by vidyadhar85
try this
Code:
 
 echo "The students are:\n""$list"

You forgot the -e option: Smilie
Code:
 
echo -e "The students are:\n""$list"

Regards
# 4  
Old 12-11-2008
Adding that -e enables backslash escape. I think it's a newer option.

Perhaps it's better to use printf in this case? For portability?
# 5  
Old 12-11-2008
Another approach

Code:
echo "The students are:" ; echo "$list"

# 6  
Old 12-11-2008
Quote:
Originally Posted by Franklin52
You forgot the -e option: Smilie
Code:
 
echo -e "The students are:\n""$list"

Regards
in AIX there is no -e option with echo so it takes "\n" or "\t" and so on...Smilie
# 7  
Old 12-11-2008
Then printf should be better for portability as nj67 mentioned or use the solution of joeyg.
Without the -e option it doesn't work on a Linux box.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo printing a line in 2 lines; expected to print in one line

Dear All, fileName: therm.txt nc3h7o2h 7/27/98 thermc 3h 8o 2 0g 300.000 5000.000 1390.000 41 1.47017550e+01 1.71731699e-02-5.91205329e-06 9.21842570e-10-5.36438880e-14 2 -2.99988556e+04-4.93387892e+01 2.34710908e+00 4.34517484e-02-2.65357553e-05 3 ... (7 Replies)
Discussion started by: linuxUser_
7 Replies

2. UNIX for Dummies Questions & Answers

Echo does not work to append to a new line

Hi, i am witing a function in a shell script which will echo the file name and witre in to the new line, but i dont get expected results. The below is my code #!/bin/bash DATE=$1 myview(){ base_name=$1 echo -ne "${base_name}${DATE}">> /path/to/file/txt } myview sample3030 myview... (5 Replies)
Discussion started by: vikatakavi
5 Replies

3. UNIX for Dummies Questions & Answers

New line in Echo command

Hi , This might sound little familar to you guys, but am struck with something. i have an IF conditioned loop which will determine a variable to get used in the later part of the script. if ; then if ; then Var_name="This is first line.This is second line.This is... (11 Replies)
Discussion started by: scott_cog
11 Replies

4. Shell Programming and Scripting

How to read in a part of an echo line?

Hello, I have a very basic script #!/usr/bin/ksh while print ' ' print ' 1. View Command History ' print ' 2. List files in current Directory ' read opt'?Enter Option> ' ;do if ;then fc -l fi # if ;then ls -la I want to... (10 Replies)
Discussion started by: Grueben
10 Replies

5. Shell Programming and Scripting

echo two command output in the same line

Hi, I try to write script and echo two command at the same line . echo "A" echo "B" How can I pipe above two command at the same line in text file . So, in the output text file , you can see below ??? A B not A B Any sugggestion ??? (4 Replies)
Discussion started by: chuikingman
4 Replies

6. Shell Programming and Scripting

Echo and a command's output on the same line

Hello, I'm writing some bash scripts and I'm trying to get an echo command and the output of another command to display on the same line. For example: I want to run echo "Operating System: " unameand have it displayed as Operating System: Darwin Thanks for your help! (7 Replies)
Discussion started by: codyhazelwood
7 Replies

7. Shell Programming and Scripting

new line in echo

Hi i would like disply the new line in echo command. i have input like: echo " X1 02:12:13 X2 03:02:12 " out put: X1 02:12:13 X2 03:02:12 can you tell how can use new line option in echo command. (5 Replies)
Discussion started by: koti_rama
5 Replies

8. Shell Programming and Scripting

Output of both the echo statement in one line

I have script like echo -n FINISHED FEXP: ${TABLE2EXP} echo $STATUS I want the output of both the echo statement in one line How can i do this (3 Replies)
Discussion started by: scorp_rahul23
3 Replies

9. Shell Programming and Scripting

echo just 1 line before execution/set +-x

Suppose that you want to mostly not echo commands inside your script during execution (e.g. to not bog the user down with details that they do not care about) but that there is the occaisional script line that you would like to echo before you execute it. Is there an elegant way to achieve this?... (3 Replies)
Discussion started by: fabulous2
3 Replies

10. Shell Programming and Scripting

how to echo the file contents LINE BY LINE

hello, i have a listing (let say ABC) consists of the below: : public database link public synonym role rollback segment : when i run the below for loop, for i in `more ABC` do echo "$i" done it gives me, : public database (4 Replies)
Discussion started by: newbie168
4 Replies
Login or Register to Ask a Question