'hhighlighter' wrapper script saying command not found

0

1

I have gotten the wrapper script 'hhighlighter' from https://github.com/paoloantinori/hhighlighter which colors anything you want in stdout. I followed the instructions about installing ack-grep, created alias for ack=ack-grep in ~/.bashrc, put the h() function in ~/.bashrc, everything works fine when typing in the terminal. But when putting the EXACT same commands in a bash script, it says command not found. I will give examples here...

root@kali:~# echo "abcd" | h a b c d
abcd

Here is what my script looks like

#!/bin/bash  
echo "abcd" | h a b c d

Exactly like the command typed in, but here is the output when running the script

root@kali:~# ./test.sh
./test.sh: line 1: h: command not found

How could this work when typing directly in the terminal, but not when having the exact same command in a bash script?

Will Hughes

Posted 2014-11-25T00:27:57.170

Reputation: 23

Question was closed 2016-04-21T16:14:31.920

Does your script begin with #!/bin/bash ? – wurtel – 2014-11-25T11:18:49.987

I reworked the question to hopefully make more sense – Will Hughes – 2014-11-25T22:36:46.413

I'm voting to close this question since it's been asked & answered at http://unix.stackexchange.com/questions/169780/hhighlighter-wrapper-script-sayi%E2%80%8C%E2%80%8Bng-command-not-found

– Sathyajith Bhat – 2016-04-21T16:14:31.920

Answers

1

Solution that helped me was to force the script to run in interactive mode with a #!/bin/bash -i header.

Advanced Bash-Scripting Guide warns about weird consequences though:

Be aware that this can cause erratic script behavior or show error messages even when no error is present.

However I haven't observed anything like this.

grinderX19

Posted 2014-11-25T00:27:57.170

Reputation: 131

0

~/.bashrc is only read during startup of an interactive bash session.

If you want it to always be read, put the name in the BASH_ENV environment variable:

export BASH_ENV=$HOME/.bashrc

wurtel

Posted 2014-11-25T00:27:57.170

Reputation: 1 359