Using color in scripts


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu Using color in scripts
# 8  
Old 04-11-2019
What output do you get from the commands:
Code:
pwd
printf '%s\n' "$PATH"
ls -l my-hilite
type env bash

when run in the directory where you installed my-hilite?
# 9  
Old 04-11-2019
Code:
andy@7_~/bin$ pwd
/home/andy/bin
andy@7_~/bin$ printf '%s\n' "$PATH"
/home/andy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
andy@7_~/bin$ ls -l my-hilite
ls: cannot access 'my-hilite': No such file or directory
andy@7_~/bin$ type env bash
env is /usr/bin/env
bash is /bin/bash

I named my script Hilite.sh if that makes a difference.
# 10  
Old 04-11-2019
Quote:
Originally Posted by drew77
Code:
andy@7_~/bin$ pwd
/home/andy/bin
andy@7_~/bin$ printf '%s\n' "$PATH"
/home/andy/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
andy@7_~/bin$ ls -l my-hilite
ls: cannot access 'my-hilite': No such file or directory
andy@7_~/bin$ type env bash
env is /usr/bin/env
bash is /bin/bash

I named my script Hilite.sh if that makes a difference.
It makes a difference.

If someone gives you a script named my_hilite and you do not install it with the name my-hilite, then you need to change everything that references my-hilite to reference whatever named you used when you installed it instead.

And, when you install it you have to make sure that the script will be readable and executable by whatever users want to run that script.

Code:
chmod 755 Hilite.sh

should give you a reasonably readable, executable script. Then you just have to find EVERYTHING that attempts to invoke my-hilite and change every reference to it to be Hilite.sh.

Last edited by Don Cragun; 04-11-2019 at 05:57 PM.. Reason: Fix typo: s/Hiliite[.]sh/Hilite.sh/
# 11  
Old 04-11-2019
Don...

Clerical error.

chmod 755 Hilite.sh not chmod 755 Hiliite.sh .
This User Gave Thanks to wisecracker For This Post:
# 12  
Old 04-11-2019
Quote:
Originally Posted by wisecracker
Don...

Clerical error.

chmod 755 Hilite.sh not chmod 755 Hiliite.sh .
Sorry, and thank you wisecracker. I have now fixed this blunder in post #10.
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 04-11-2019
I renamed it back to orig name.

Code:
my-hilite.sh

-----
 Results, file missing:
/home/andy/bin/my-hilite.sh: line 24: my-hilite: command not found

-----
 Results, file present:
/home/andy/bin/my-hilite.sh: line 32: my-hilite: command not found

-----
 Results, if only string "File" should be colored:
/home/andy/bin/my-hilite.sh: line 40: my-hilite: command not found

The scripts is relying on my-hilite which does not exist.

Code:
else
  echo "File $FILE does NOT exist." |
  my-hilite -f red

# 14  
Old 04-11-2019
Hi drew77...
Quote:
The scripts is relying on my-hilite which does not exist.
Of course it doesn't it is named my-hilite NOT my-hilite.sh .
Try mv my-hilite.sh my-hilite and retry...
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Text color in Linux scripts via putty

hi Folks, Can anyone help with changing the color of the words in a linux shell script? I get how to change default background etc in putty, but for some reason the text in the script has different colors for different parts of the cript. Is there a way to have one color in a linux shell... (5 Replies)
Discussion started by: jonnyd
5 Replies

2. UNIX for Dummies Questions & Answers

How to change the background color in the init 3 mode(not line color)

Hello, I am using RHEL 6.1 on VMware I am searching for a way to change background color (not line by line color wich one can using tput command) basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
Discussion started by: Dexobox
2 Replies
Login or Register to Ask a Question