0

I added my script called mylovelyscript.sh to /bin/ folder. My script contains code that echos text with different text colors. But when I run my script like

$ mylovelyscript

it executes in bash mode. So, my script give an output with the texts with color codes, like

\e[93mHello World!

but not colored texts. But when I run my script like $ sh mylovelyscript.sh with sh command, it executes like how I want. Now, I want my script to give me colored texts like in sh mode, but in this case I want to call my script like $ mylovelyscript, not like $ sh mylovelyscript. How can I do it? Thanks!

4

Put this line at the beginning of the file:

#!/bin/sh

or:

#!/bin/dash

  • Thanks @Wutaz! I think that it will work. I have a one problem, not related with this problem: I switched to sh mode, as you said, but know I need to change bash code to sh code, as sh can't read bash style code. – Ziyaddin Sadigov Feb 26 '14 at 18:17
  • Didn't you say you were running it with sh? – Wutaz Feb 26 '14 at 18:22
  • no, I was running it with bash, I need to do it on sh, in my script there is for...loop which I wrote for bash, I need to change it for sh mode. – Ziyaddin Sadigov Feb 26 '14 at 18:27
  • is there any way to do it in bash mode? To make colored texts in bash mode? – Ziyaddin Sadigov Feb 26 '14 at 18:43
  • You said you ran it with $ sh mylovelyscript.sh. – Wutaz Feb 26 '14 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.