Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

echo -e working in terminal but not in bash script

Tags:

bash

shell

I developed and maintain a ruby gem called Githug and I am trying to write an automated test script for it. Githug basically manipulates a directory to put it into different states of a working git repository and you can execute git commands to "solve" the level.

One of the levels asks you for your git config details and I am doing the following:

#! /bin/sh
# ...snip
#level 4
FULL_NAME=$(git config --get user.name)
EMAIL=$(git config --get user.email)
echo -e "$FULL_NAME\n$EMAIL" | githug

When I execute from a bash script it (echo -e) doesn't work. But it does when I run it from the terminal.

FULL_NAME=$(git config --get user.name)
EMAIL=$(git config --get user.email)
echo -e "$FULL_NAME\n$EMAIL" | githug
********************************************************************************
*                                    Githug                                    *
********************************************************************************
What is your name? What is your email?
Congratulations, you have solved the level

Why doesn't this work from the bash script?

Thanks.

like image 592
Gazler Avatar asked Apr 22 '12 12:04

Gazler


People also ask

Does echo work in bash?

The echo command is one of the most commonly and widely used built-in commands for Linux bash and C shells, that typically used in a scripting language and batch files to display a line of text/string on standard output or a file. 2.

How do you echo something in shell script?

The echo command writes text to standard output (stdout). The syntax of using the echo command is pretty straightforward: echo [OPTIONS] STRING... Some common usages of the echo command are piping shell variable to other commands, writing text to stdout in a shell script, and redirecting text to a file.

How do I fix bash permission denied?

Usually, you get the error bash permission denied when running some script/file that does not have execute permissions. All you need to do is to change file permissions and add executive one.


1 Answers

Wrong shebang:

#! /bin/sh

When it shall be a bash script, use

#! /bin/bash

Bash has a buildin echo, which isn't 100% identic with /bin/echo.

like image 174
user unknown Avatar answered Oct 17 '22 22:10

user unknown