LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 06-27-2015, 04:39 AM   #1
johanna
LQ Newbie
 
Registered: Jun 2015
Location: Dallas, TX
Distribution: Debian Stable
Posts: 8

Rep: Reputation: Disabled
Lightbulb simple .bashrc if-request modification needed


Hi guys,

I just made it and got my terminl set up (with tmux) 256 color support. While setting everything up I saw that $TERM is screen, whilst I thought I use xterm. So I had to adjust my .bashrc and added the last three lines:

Code:
 
# enable 256 colors support
if [ "$TERM" == "xterm" ]; then
  export TERM=xterm-256color
fi

if [ "$TERM" == "screen" ]; then
  export TERM=screen-256color
fi
However, I believe there must be a slicker way to do that.
I'm quite new to all of this, so I hope you can help me out.

Thanks. J.
 
Old 06-27-2015, 06:38 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
You could always use a case statement instead of an if.

One reason what you have may cause a problem is if you had more options... where an earlier selection would conflict with one that follows. The case statement doesn't have that problem:
Code:
# enable 256 colors support
case $TERM in
xterm)   export TERM=xterm-256color
         ;;
screen)  export TERM=screen-256color
         ;;
esac
The advantage is that only one option would be selected, and only one test. You could do the same
using an if, but it would be structured as "if... elif ... fi"
 
Old 06-27-2015, 08:06 AM   #3
johanna
LQ Newbie
 
Registered: Jun 2015
Location: Dallas, TX
Distribution: Debian Stable
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hey jpollard,

perfect solution! I was thinking about

Code:
# enable 256 colors support
if [ "$TERM" == "xterm" ]; then
XXX=xterm
fi
if [ "$TERM" == "screen" ]; then
XXX=screen
fi

export TERM=$XXX-256color
but it is not really slicker. Your solution is really nice.
Thanks for helping me learn.

J
 
  


Reply

Tags
bash, bashrc



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
ns2 Simple MAC protocol modification for adding primary users in cognitive radio MahmoudAlaa Programming 9 07-23-2014 03:00 AM
Request for modification of installation folders samac Slackware 1 10-03-2012 12:33 PM
simple question about .dmrc .bashrc MOFH Linux - Newbie 3 11-25-2009 02:58 PM
Simple script request Tortanick Programming 5 12-06-2006 05:33 PM
Simple request regarding route The Joker Linux - Networking 2 11-18-2005 06:01 PM

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

All times are GMT -5. The time now is 10:56 AM.

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