What does a bash script return?

What does a bash script return?

Unlike functions in “real” programming languages, Bash functions don’t allow you to return a value when called. When a bash function completes, its return value is the status of the last statement executed in the function, 0 for success and non-zero decimal number in the 1 – 255 range for failure.

How does a bash script return a value?

When a bash function ends its return value is its status: zero for success, non-zero for failure. To return values, you can set a global variable with the result, or use command substitution, or you can pass in the name of a variable to use as the result variable.

Why do I get an unexpected end of file error in Bash?

This can happen if you create your script using Windows. Why? Because Windows uses a combination of two characters, Carriage Return and Line Feed, as line break in text files (also known as CRLF). On the other side Unix (or Linux) only use the Line Feed character as line break.

What’s the syntax error for unexpected end of file?

Here’s the code: #!/bin/bash # june 2011 if [ $# -lt 3 -o $# -gt 3 ]; then echo “Error… Usage: $0 host database username” exit 0 fi after running sh file.sh: syntax error: unexpected end of file bashsyntax Share Improve this question Follow edited Jun 17 ’13 at 10:26 fedorqui ‘SO stop harming’

How to convert Bash end of file to Unix format?

[ec2-user@localhost scripts]$ dos2unix end_of_file.sh dos2unix: converting file end_of_file.sh to Unix format It works! If you are interested I have written an article that explains the basics of Bash script arguments.

What to do if you get an error in Bash?

Asked10 years, 1 month ago Active1 year ago Viewed271k times 121 34 Forgive me for this is a very simple script in Bash. Here’s the code: #!/bin/bash # june 2011 if [ $# -lt 3 -o $# -gt 3 ]; then echo “Error… Usage: $0 host database username” exit 0 fi after running sh file.sh: