LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-05-2015, 12:42 PM   #1
Defested
LQ Newbie
 
Registered: Mar 2015
Posts: 9

Rep: Reputation: Disabled
Print single quotes within an echo appending to the end of a file.


Hello all,
I am working on setting up a script to set certain things and install them on new installs of linux, however I am running into an issue with appending code onto the end of my .bashrc.

I am trying to append
Code:
PS1='\033[1;32m[\A \u@\h \W]\033[0m$ '
into .bashrc and I have tried the following methods without success
Code:
echo PS1='\[\e[1;31m\][\A \u@\h \W]\$\[\e[0m\] ' >> /root/.bashrc
echo 'PS1='\[\e[1;31m\][\A \u@\h \W]\$\[\e[0m\] '' >> /root/.bashrc
echo 'PS1=\'\[\e[1;31m\][\A \u@\h \W]\$\[\e[0m\] \'' >> /root/.bashrc
echo "PS1='\[\e[1;31m\][\A \u@\h \W]\$\[\e[0m\] '" >> /root/.bashrc
as well as several others with not avail. the issue is that echo is interpreting the single quotes that I would like printed. I have tried escaping them with not luck. any ideas?
 
Old 03-05-2015, 12:48 PM   #2
Defested
LQ Newbie
 
Registered: Mar 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
I have figured it out, it requires some wierd syntax but it is
Code:
echo 'PS1='"'"'\[\e[1;31m\][\A \u@\h \W]\$\[\e[0m\] '"'"'' >> /root/.bashrc
does anyone have a better way?
 
Old 03-05-2015, 05:55 PM   #3
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,631

Rep: Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711
This works for me in bash:
Code:
jlinkels@donald-pc:~$ echo "PS1='\033[1;32m[\A \u@\h \W]\033[0m$ '" >> /tmp/foo
jlinkels@donald-pc:~$ cat /tmp/foo
PS1='\033[1;32m[\A \u@\h \W]\033[0m$ '
jlinkels

Last edited by jlinkels; 03-05-2015 at 05:59 PM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Problem echoing text to shell file with quotes in the middle of the echo command AntBla Linux - Newbie 2 02-16-2014 05:56 AM
[SOLVED] Difference between echo of file within double quotes and without double quotes ankitpandey Programming 2 01-11-2013 09:02 AM
translate value from single quotes to double quotes venkateshrupineni Linux - Newbie 2 06-14-2012 03:03 PM
Using single quotes vs double quotes in PHP strings vharishankar Programming 6 07-11-2005 11:41 AM
replacing single quotes in file names adenardo Linux - General 2 05-27-2005 11:29 AM

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

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