LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-01-2017, 07:07 PM   #1
James Roam Cheatham
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Rep: Reputation: Disabled
Trying to customize grub colors using sed in a terminal.


Hi Gang, I've been writing scripts, both for myself and for new users to linux, I have recently been working on a way to alter the grub menu appearance via terminal and I have stumbled up on a rut. I normally use sed to replace or alter a line in a system file(including /etc/default/grub itself), but sed -i -e '/GRUB_COLOR_NORMAL="light-gray/black"/c\GRUB_COLOR_NORMAL="white/black" ' /etc/default/grub for instance doesn't give me the desired effect. I have used several variations of sed commands to change them, but in the end, I'm lost. Please tell me where I might have went wrong.
 
Old 11-02-2017, 02:57 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
you need to escape literal forward slashes (and possibly other characters) like this: \/

also, your problem description lacks basic troubleshooting procedure.
 
Old 11-02-2017, 03:34 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,879

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
or, if you use / in your expressions you can use another delimiter.
 
Old 11-02-2017, 10:41 PM   #4
James Roam Cheatham
LQ Newbie
 
Registered: Nov 2017
Posts: 2

Original Poster
Rep: Reputation: Disabled
It looks kinda like this right now.



color=$(sudo sed -i -e '/GRUB_COLOR_NORMAL="light-gray/black"/c\GRUB_COLOR_NORMAL="$color" ' /etc/default/grub)
Highlight=$(sudo sed -i -e '/GRUB_COLOR_HIGHLIGHT="green/black"/c\GRUB_COLOR_HIGHLIGHT="$Highlight" ' /etc/default/grub)
background=$(sudo sed -i -e '/GRUB_BACKGROUND="/usr/share/grub/background.png"/c\GRUB_BACKGROUND="$background" ' /etc/default/grub)
theme=$(sudo sed -i -e '/GRUB_THEME="/path/to/gfxtheme"/c\GRUB_THEME="$theme" ' /etc/default/grub)

echo "Choose a number between 1 and 5"

echo "1 - Changing the color"
echo "2 - Changing the Highlight"
echo "3 - Changing the background"
echo "4 - Changing the theme"
echo "5 - Doing all the above"

read customization;

case $customization in
1) sudo sed -i -e '/GRUB_COLOR_NORMAL="light-gray/black"/c\GRUB_COLOR_NORMAL="red/black" ' /etc/default/grub ;;
2) sudo sed -i -e '/GRUB_COLOR_HIGHLIGHT="green/black"/c\GRUB_COLOR_HIGHLIGHT="$Highlight" ' /etc/default/grub ;;
3) sudo sed -i -e '/GRUB_BACKGROUND="/usr/share/grub/background.png"/c\GRUB_BACKGROUND="$background" ' /etc/default/grub ;;
4) sudo sed -i -e '/GRUB_THEME="/path/to/gfxtheme"/c\GRUB_THEME="$theme" ' /etc/default/grub ;;
5) $color && $Highlight && $background && $theme
esac
 
Old 11-03-2017, 01:57 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,879

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
please use [code]here comes your script[/code] tags to keep original formatting.

And it is now ok for you? Or is there any problem with that?
 
Old 11-04-2017, 12:29 PM   #6
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,800

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Your sample from post#1 can be improved like this
Code:
sed -i '/GRUB_COLOR_NORMAL=/ s|light-gray/black|white/black|' /etc/default/grub
The s (substitute) command replaces only the right side.
The | delimiter does not clash with the / characters in the search and substitution strings.
A rather theoretic problem with this is, the /search/ can match on the right side and the |search| can match on the left side.
If you want to fly to the moon you are better off with
Code:
sed -i 's|\(GRUB_COLOR_NORMAL=\)"light-gray/black"|\1"white/black"|' /etc/default/grub
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Customize GTK3 / GTK2 Theme Colors Using `GTK Theme Preferences` LXer Syndicated Linux News 0 09-08-2012 02:00 PM
LXer: Grub Customizer 2.5.5 is available- Customize grub/Burg from a GUI interface LXer Syndicated Linux News 0 05-10-2012 09:20 PM
Customize terminal in gnome sn68 Fedora 3 10-03-2006 10:46 AM
Customize the look of my terminal??? Southpaw76 *BSD 3 07-28-2006 06:27 PM
How do I customize background/foreground colors in Eclipse? wearetheborg Linux - Newbie 0 09-10-2004 02:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:46 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