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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With