LinuxQuestions.org
Review your favorite Linux distribution.
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-02-2014, 05:05 AM   #1
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Rep: Reputation: Disabled
Bash coloring on a script output...


I am using Debian 7.
When I type a command from the terminal, ex. "ls -lha", I get the output colored correctly, relative to my .bashrc file.
However, when I use the same command from a bash script such as:
#!/bin/bash
ls -lha
I get no color on the output... Does anyone have an idea why this is so?
I connected also connected via ssh, but I don't think that is relevant.

I find coloring of folders very useful, and would love to have this.

Thanks in advance

Last edited by cab00t; 06-02-2014 at 05:08 AM.
 
Old 06-02-2014, 05:08 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,488

Rep: Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427
you need to check how ls works. Probably it is an alias set in ~/.bashrc therefore this alias will not work in a shell script.
 
1 members found this post helpful.
Old 06-02-2014, 05:13 AM   #3
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
Exactly

Running "cat ~/.bashrc | grep ls" returned:
alias ls='ls --color=auto' #among other things
I added "--color=auto" to the end of the command on my script and now it works.
Thank you very much for your reply, still trying to grasp all this... An ex Windows user.
 
Old 06-02-2014, 05:15 AM   #4
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
Btw, what do you think is better, using aliases vs adding a folder to $PATH with bash scripts for similar things?
 
Old 06-02-2014, 05:18 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,488

Rep: Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427
glad to help you
grep ls ~/.bashrc would be enough, without cat
(if you really want say thanks just press yes)
 
2 members found this post helpful.
Old 06-02-2014, 05:20 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,488

Rep: Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427Reputation: 2427
Quote:
Originally Posted by cab00t View Post
Btw, what do you think is better, using aliases vs adding a folder to $PATH with bash scripts for similar things?
read the man page of bash, how login works and what is the purpose of ~/.bashrc and related files. Usually every user can have a bin in his home and add it to $PATH, but it really depend on you.
 
Old 06-02-2014, 05:21 AM   #7
Randicus Draco Albus
Senior Member
 
Registered: May 2011
Location: Hiding somewhere on planet Earth.
Distribution: OpenBSD
Posts: 1,644
Blog Entries: 8

Rep: Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577
Quote:
Originally Posted by cab00t View Post
... still trying to grasp all this... An ex Windows user.
Quote:
adding a folder to $PATH
Not trying to be a prick, but since you are in the process of grasping things (like the rest of us), here is my contribution. Folder is Windows speak. In UNIX systems files are kept inside directories. (Nothing personal. It is just one of my pet peeves.)
 
2 members found this post helpful.
Old 06-02-2014, 05:24 AM   #8
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
Will do, thanks for more input pan64.
Randicus, I appreciate the correction, we need to try to be exact when speaking...

Last edited by cab00t; 06-02-2014 at 05:58 AM.
 
Old 06-02-2014, 05:43 AM   #9
Randicus Draco Albus
Senior Member
 
Registered: May 2011
Location: Hiding somewhere on planet Earth.
Distribution: OpenBSD
Posts: 1,644
Blog Entries: 8

Rep: Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577
Quote:
Originally Posted by cab00t View Post
we need to try to be exact when speaking...

Quote:
Radicus, I appreciate the correction,
 
Old 06-02-2014, 05:58 AM   #10
cab00t
LQ Newbie
 
Registered: Nov 2012
Location: Montenegro
Distribution: Debian, ArchLinux, Mint, Kali
Posts: 22

Original Poster
Rep: Reputation: Disabled
*Randicus Draco Albus, sorry mate.
 
Old 06-02-2014, 07:05 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,254

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
I almost wish you hadn't said this ...
Quote:
Folder is Windows speak. In UNIX systems files are kept inside directories. (Nothing personal. It is just one of my pet peeves.)
... but I have to admit it bugs me too

I think I've almost never pointed it out, but I do ALWAYS say 'dir' in my answers, even if the qn uses 'folder'
 
1 members found this post helpful.
Old 06-02-2014, 08:28 AM   #12
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,657
Blog Entries: 10

Rep: Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075Reputation: 2075
Quote:
Originally Posted by pan64 View Post
glad to help you
grep ls ~/.bashrc would be enough, without cat
(if you really want say thanks just press yes)
and as usual there are many ways to do it in Linux:
Code:
alias ls
or
Code:
type ls
None is "correct" but less typing IS less typing.

Have a great day!
 
Old 06-02-2014, 10:16 PM   #13
Randicus Draco Albus
Senior Member
 
Registered: May 2011
Location: Hiding somewhere on planet Earth.
Distribution: OpenBSD
Posts: 1,644
Blog Entries: 8

Rep: Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577Reputation: 577
Quote:
Originally Posted by chrism01 View Post
I almost wish you hadn't said this ...

... but I have to admit it bugs me too

I think I've almost never pointed it out, but I do ALWAYS say 'dir' in my answers, even if the qn uses 'folder'
But I am becoming a grumpy old man.
 
Old 06-03-2014, 05:51 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,254

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Saves me doing it then haha
 
Old 06-03-2014, 11:47 PM   #15
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 811

Rep: Reputation: 264Reputation: 264Reputation: 264
Quote:
Originally Posted by Randicus Draco Albus View Post
Not trying to be a prick, but since you are in the process of grasping things (like the rest of us), here is my contribution. Folder is Windows speak. In UNIX systems files are kept inside directories. (Nothing personal. It is just one of my pet peeves.)
I usually try to use "directory" but sometimes "folder" slips out. :embarrassed: But I still use "folder" when walking my mom through copying pictures, just to keep it simpler for her.

"directory" is longer to say (and type!) than "folder" though...
 
  


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] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 03:57 PM
LXer: Coloring grep output to easier research in your Linux terminal LXer Syndicated Linux News 0 11-25-2012 05:11 PM
[SOLVED] bash coloring output Jerry Mcguire Programming 1 08-11-2011 02:44 AM
coloring TAB output for filename completion glinux Linux - Newbie 0 03-02-2009 11:34 PM
bash ls not coloring files, directories etc mr_smith Red Hat 2 08-30-2006 08:05 AM


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