LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash coloring on a script output... (https://www.linuxquestions.org/questions/linux-newbie-8/bash-coloring-on-a-script-output-4175506740/)

cab00t 06-02-2014 04:05 AM

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 :)

pan64 06-02-2014 04:08 AM

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.

cab00t 06-02-2014 04:13 AM

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. :)

cab00t 06-02-2014 04:15 AM

Btw, what do you think is better, using aliases vs adding a folder to $PATH with bash scripts for similar things?

pan64 06-02-2014 04:18 AM

glad to help you
grep ls ~/.bashrc would be enough, without cat
(if you really want say thanks just press yes)

pan64 06-02-2014 04:20 AM

Quote:

Originally Posted by cab00t (Post 5180714)
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.

Randicus Draco Albus 06-02-2014 04:21 AM

Quote:

Originally Posted by cab00t (Post 5180711)
... 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.):)

cab00t 06-02-2014 04:24 AM

Will do, thanks for more input pan64.
Randicus, I appreciate the correction, we need to try to be exact when speaking... :)

Randicus Draco Albus 06-02-2014 04:43 AM

Quote:

Originally Posted by cab00t (Post 5180720)
we need to try to be exact when speaking... :)

:hattip:
Quote:

Radicus, I appreciate the correction,
:eek:

cab00t 06-02-2014 04:58 AM

*Randicus Draco Albus, sorry mate. :D

chrism01 06-02-2014 06:05 AM

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'
:)

Habitual 06-02-2014 07:28 AM

Quote:

Originally Posted by pan64 (Post 5180717)
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!

Randicus Draco Albus 06-02-2014 09:16 PM

Quote:

Originally Posted by chrism01 (Post 5180764)
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.:D

chrism01 06-03-2014 04:51 AM

Saves me doing it then haha :)

maples 06-03-2014 10:47 PM

Quote:

Originally Posted by Randicus Draco Albus (Post 5180719)
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...


All times are GMT -5. The time now is 05:40 PM.