Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

very simple OSX bash script: echo gives no output

Tags:

bash

macos

I'm running OSX 10.6, and I have this very simple script in a file "hi.sh":

#!/bin/bash
echo "hi"

I've already run "chmod +x hi.sh". Now, I've tried both of the following:

$ ./hi.sh
$ bash hi.sh

and neither outputs "hi". What could be the problem?

like image 779
maackle Avatar asked Feb 11 '11 08:02

maackle


People also ask

What is echo $$ in Bash?

The echo command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file.

What does echo command do in Mac?

This prints the specified text string before producing a listing of all the files in the current working directory, across the screen. echo recognizes a number of escape sequences which it expands internally. An escape command is a backslash-escaped character that signifies some other character.


1 Answers

It could be that you used an editor that defaults to \r as line separator, which was the separator used under classic (pre OS X) MacOS. Try wc -l hi.sh; if you get 0 lines, then it's a line ending problem. Your script would then be just a single comment line, which would of course do nothing.

like image 155
Michael J. Barber Avatar answered Oct 04 '22 08:10

Michael J. Barber