LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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, 06: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, 06:51 AM   #2
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Bangalore, India
Distribution: Linux Mint 13
Posts: 592

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, 06:57 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

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 07:03 AM.
 
Old 03-17-2010, 08: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 08:29 AM.
 
Old 03-17-2010, 08:34 AM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

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 08:44 AM.
 
  


Reply

Tags
echo, error


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 03:08 AM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 05:23 AM
Command "mail" returns "panic: temporary file seek" kenneho Linux - Software 5 12-23-2008 04:27 AM
BASH: How to NOT echo to screen with "if echo $x | grep ".*"; then" eur0dad Programming 9 07-27-2006 03:14 PM
Error in man command "sh: line 1: /usr/bin/gtbl: No such file or directory" MinA Slackware 1 09-06-2004 07:36 PM


All times are GMT -5. The time now is 06:06 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration