Visit Our UNIX and Linux User Community

Echo does not work to append to a new line

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Echo does not work to append to a new line
# 1  
Old 09-15-2014
Echo does not work to append to a new line


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

echo -ne "${base_name}${DATE}">>  /path/to/file/txt
myview sample3030
myview sample2020

i am excepting results as


But i get the results as

sample303020140101 sample202020140101

any idea what i am doing worng would help me.


Last edited by Scrutinizer; 09-15-2014 at 06:56 PM.. Reason: code tags
# 2  
Old 09-15-2014
echo -e "${base_name}${DATE}">> /path/to/file/txt

This User Gave Thanks to wisecracker For This Post:
# 3  
Old 09-15-2014
Originally Posted by wisecracker
echo -e "${base_name}${DATE}">> /path/to/file/txt

Hi wisecracker,

Thanks for the reply,i tried the above code but i still see the same results.
# 4  
Old 09-15-2014
Change the echo to print...
This User Gave Thanks to shamrock For This Post:
# 5  
Old 09-15-2014
Minor re-write...
OSX 10.7.5, default bash terminal:-
> /tmp/txt
	echo "$base_name$DATE" >> /tmp/txt
myview sample3030
myview sample2020
cat /tmp/txt
exit 0

Last login: Mon Sep 15 22:13:52 on ttys000
AMIGA:barrywalker~> chmod 755
AMIGA:barrywalker~> ./ "9th_October_2014"
AMIGA:barrywalker~> _

This User Gave Thanks to wisecracker For This Post:
# 6  
Old 09-15-2014
Do not use echo -e, do not use echo -n.
printf "%s\n" "mystring"

This User Gave Thanks to Corona688 For This Post:

Previous Thread | Next Thread
Test Your Knowledge in Computers #251
Difficulty: Easy
MILNET was designed for highly classified military communications.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SED and Solaris Append line to the end of File does not work

Hello, I have to add a new line at the end of a File on Solaris-System: I think my script should be right, because I evaluated it to other threads. However the script does not what I am expected it should do. My file might look like this: Line1 Line2 Line3 And my script could... (7 Replies)
Discussion started by: Timo_HR
7 Replies

2. Shell Programming and Scripting

echo doesn't work right

Hi,when I run my first shell script,I got something that doesn't work right. I wrote this code in the script. echo -e "Hello,World\a\n"But the screen print like this: -e Hello,World The "-e" wasn't supposed to be printed out. Can anyone help me out?:wall: Many thanks!:) (25 Replies)
Discussion started by: Demon
25 Replies

3. Shell Programming and Scripting

Color on echo output does not work

Hi, When I run: echo "\033I see hi in color, but if I run this color is not shown, why? (echo "\033Thanks Israel. ---------- Post updated at 05:17 AM ---------- Previous update was at 04:43 AM ---------- DONE!! I had to run more -v. Thanks (4 Replies)
Discussion started by: iga3725
4 Replies

4. UNIX for Dummies Questions & Answers

'echo dir_path | xargs cd' does not work?

Hi: how come this command does not work? the error message is: xargs: cd: No such file or directory yet, in the same time, 'echo dir_path | xargs ls' works. Does it work in bash? We use csh. Thanks. NB Phil (7 Replies)
Discussion started by: phil518
7 Replies

5. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

6. Shell Programming and Scripting

echo $PWD doesn't work

I have entry in the my .profile like below, but still i see $PWD is not defied in my system export PS1=$LOGNAME@`hostname`':'$PWD'>' echo $PWD also gives me nothing, my env list also give no entry for PWD.Can someone help me setting PWD variable. I use /bin/sh (9 Replies)
Discussion started by: yesmani
9 Replies

7. Shell Programming and Scripting

if [ -z echo foo | egrep -e 'regexp' != '' ] -> dont work

Hallo, I need to test a String (a special ip number-string). So I want to run that: ipadress= # for debugging: echo $ipadress | egrep -e '172\.?\.??\.??$' # the test that doesnt work if test -z `echo $ipadress | egrep -e '172\.?\.??\.??$'` != "" then echo "match" else... (1 Reply)
Discussion started by: wiseguy
1 Replies

8. Shell Programming and Scripting

Append Status to echo'd line after process completes

Hello All, I'm very new to scripting and I'm writing a very simple script to restart a couple processes because I'm getting to lazy to cd between directories. This is pretty much my first script and I just want to add a little cosmetics to it. Here's what I have: #!/bin/ksh echo... (5 Replies)
Discussion started by: Setan
5 Replies

9. UNIX for Dummies Questions & Answers

bash pattern matching echo *[! '/' ] doesn't work

without using ls, just using echo so purely pattern matching I can say echo */ <-- lists directories but how would I match files? surely something like *!/ or * but neither work ? it seems like there isn't much that I can put in but surely i should be able to put any ascii... (1 Reply)
Discussion started by: james hanley
1 Replies

10. Shell Programming and Scripting

echo, append to end of file

I need the line printed with echo to append to eof of to exactly line, am i able to do that? i mean echo "sysctl -w lalala=1" > to end of file /etc/sysctl.conf or to the 21st line, if the line exist, open new line and insert text there. Thx.maybe i'm in wrong topic but anyway... (2 Replies)
Discussion started by: hachik
2 Replies

Featured Tech Videos