Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Put this line at the beginning of the file:

#!/bin/sh

or:

#!/bin/dash

share|improve this answer
    
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 at 18:17
    
Didn't you say you were running it with sh? –  Wutaz Feb 26 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 at 18:27
    
is there any way to do it in bash mode? To make colored texts in bash mode? –  Ziyaddin Sadigov Feb 26 at 18:43
    
You said you ran it with $ sh mylovelyscript.sh. –  Wutaz Feb 26 at 20:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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