LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 02-07-2013, 06:42 PM   #1
gdizzle
Member
 
Registered: Jul 2012
Posts: 197

Rep: Reputation: Disabled
Question Bash / Sed help?


Hi All,
I need to insert:

Code:
prompt=(\\u@\\h) [\\d]>\\_
Into my /etc/my.cnf file via a bash script using either echo or sed.

I am going a bit crazy can anyone please assist?

Thanks
 
Old 02-07-2013, 06:58 PM   #2
evo2
Senior Member
 
Registered: Jan 2009
Location: Japan
Distribution: Debian
Posts: 4,833

Rep: Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024Reputation: 1024
Hi,

the following works in zsh

Code:
echo 'prompt=(\\\\u@\\\\h) [\\\\d]>\\\\_' >> /etc/my.cnf
If you are using bash I don't think you need to escape the backslashes, so:
Code:
echo 'prompt=(\\u@\\h) [\\d]>\\_' >> /etc/my.cnf
What shell are you using?

Evo2.

EDIT: oops I see now that you already specified bash.

Last edited by evo2; 02-07-2013 at 07:00 PM.
 
Old 02-07-2013, 06:59 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,093

Rep: Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995Reputation: 1995
Code:
echo 'prompt=(\\u@\\h) [\\d]>\\_' >t.t

cat t.t

prompt=(\\u@\\h) [\\d]>\\_
 
Old 02-07-2013, 07:04 PM   #4
gdizzle
Member
 
Registered: Jul 2012
Posts: 197

Original Poster
Rep: Reputation: Disabled
Thanks chrism01!

I was doing echo -e and having issues....

This solved it: echo 'prompt=(\\u@\\h) [\\d]>\\_' >> /etc/my.cnf

Thanks evo2 also for your reply!

---------- Post added 02-08-13 at 02:05 AM ----------

Thanks chrism01!

I was doing echo -e and having issues....

This solved it: echo 'prompt=(\\u@\\h) [\\d]>\\_' >> /etc/my.cnf

Thanks evo2 also for your reply!
 
Old 02-09-2013, 10:55 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
There are lots of ways to add text to a file, the simplest of which don't require any external commands, just a '>>' redirect.

A slightly more complex one, which can be used to add multiple lines at once, is a here document.

Code:
cat >>/etc/my.cnf  <<"ENDSTRING"
newline1
newline2
newline3
ENDSTRING
All of the text between the ENDSTRINGS will be directed as-is to the file. The quote marks around the first ENDSTRING keep any variable names or other patterns from expanding. Remove them if you want substitutions to be done before printing.

http://mywiki.wooledge.org/BashGuide...nd_Herestrings

For more advanced editing work inside scripts, such as inserting lines at the beginning of a file, you do generally have to use an external command. But instead of sed, consider using ed.


http://wiki.bash-hackers.org/howto/edit-ed
http://snap.nlc.dcccd.edu/learn/nlc/ed.html
(also read the info page)
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Sed Help CodyK479 Programming 11 03-26-2011 11:03 AM
sed in BASH ovince Programming 2 11-16-2007 12:55 AM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
bash - sed/tr??? pk21 Programming 2 09-05-2003 07:56 AM
bash - sed pk21 Programming 6 03-07-2003 11:02 AM


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

Main Menu
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