LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2010, 05:49 AM   #1
muby
LQ Newbie
 
Registered: Oct 2007
Posts: 28

Rep: Reputation: 15
echo command error "file exits"


Hi Everyone,

I faced a issue with updating a file contents with echo command which fails with error as below:

echo "foo" > bar //to create a file named "bar"
echo "foobar" > bar //to edit its contents

The latter fails, it prompts "File exists"

i.e.

~>echo "foo" > bar
~>echo "foobar" > bar
bar: File exists.
~>cat bar
foo
~>

anybody had similar issue or know how to fix this?
Thanks
 
Old 03-17-2010, 05:51 AM   #2
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 624

Rep: Reputation: 64
Quote:
Originally Posted by muby View Post
Hi Everyone,

I faced a issue with updating a file contents with echo command which fails with error as below:

echo "foo" > bar //to create a file named "bar"
echo "foobar" > bar //to edit its contents

The latter fails, it prompts "File exists"

i.e.

~>echo "foo" > bar
~>echo "foobar" > bar
bar: File exists.
~>cat bar
foo
~>

anybody had similar issue or know how to fix this?
Thanks
Try this:
echo "foobar" >> bar
 
Old 03-17-2010, 05:57 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Check the output of
Code:
echo $-
himBCH
If you find the C in the output, it indicates it won't allow existing file to overwirte.

You may turn it off using
Code:
set -o noclobber off
After creating file
Quote:
echo "foo" > bar //to create a file named "bar"
You will not be able to perform below operation, if noclobber option is set to ON. I guess this is your problem.
Code:
echo "foobar" > bar
To edit the file. Personally, It is better if you open the file using Vi and edit.

Last edited by vinaytp; 03-17-2010 at 06:03 AM.
 
Old 03-17-2010, 07:08 AM   #4
muby
LQ Newbie
 
Registered: Oct 2007
Posts: 28

Original Poster
Rep: Reputation: 15
Thanks vinaytp & sayan_acharjee for your replies,

when i run the command, i get this error
Code:
~>echo $-
Illegal variable name.
is it dependent on which shell i use? I'm using tcsh


Edit: regardless, this was solved with

Quote:
set -o noclobber off
Thanks a lot

Last edited by muby; 03-17-2010 at 07:29 AM.
 
Old 03-17-2010, 07:34 AM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
I have not used tcsh. Yes I checked with tcsh, it will not support $- variable.

You have to check shell properties to find alternative for $-

Last edited by vinaytp; 03-17-2010 at 07:44 AM.
 
  


Reply

Tags
echo, error



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command logging ideas needed! ssh user@host "echo logme" ZiGz Linux - Security 6 04-15-2009 02:08 AM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 04:23 AM
Command "mail" returns "panic: temporary file seek" kenneho Linux - Software 5 12-23-2008 03:27 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 02:14 PM
Error in man command "sh: line 1: /usr/bin/gtbl: No such file or directory" MinA Slackware 1 09-06-2004 06:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration