Exercism: Bash version of the 'Hello World' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.5 KiB

3 years ago
  1. # Hello World
  2. The classical introductory exercise. Just say "Hello, World!".
  3. ["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
  4. the traditional first program for beginning programming in a new language
  5. or environment.
  6. The objectives are simple:
  7. - Write a function that returns the string "Hello, World!".
  8. - Run the test suite and make sure that it succeeds.
  9. - Submit your solution and check it at the website.
  10. If everything goes well, you will be ready to fetch your first real exercise.
  11. # Welcome to Bash!
  12. Unlike many other languages here, bash is a bit of a special snowflake.
  13. If you are on a Mac or other unix-y platform, you almost definitely
  14. already have bash. In fact, anything you type into the terminal is
  15. likely going through bash.
  16. The downside to this is that there isn't much of a development
  17. ecosystem around bash like there is for other languages, and there are
  18. multiple versions of bash that can be frustratingly incompatible. Luckily
  19. we shouldn't hit those differences for these basic examples, and if you
  20. can get the tests to pass on your machine, we are doing great.
  21. ## Installation
  22. As mentioned above, if you are on a unix-like OS (Mac OS X, Linux, Solaris,
  23. etc), you probably already have bash.
  24. ## Testing
  25. As there isn't much of a bash ecosystem, there also isn't really a de
  26. facto leader in the bash testing area. For these examples we are using
  27. [bats](https://github.com/bats-core/bats-core). You should be able to
  28. install it from your favorite package manager, on OS X with homebrew
  29. this would look something like this:
  30. ```
  31. $ brew install bats
  32. ==> Downloading
  33. https://github.com/bats-core/bats-core/archive/v1.2.0.tar.gz
  34. ==> Downloading from
  35. https://codeload.github.com/bats-core/bats-core/tar.gz/v1.2.0
  36. ########################################################################
  37. 100.0%
  38. ==> ./install.sh /opt/boxen/homebrew/Cellar/bats/1.2.0
  39. 🍺 /opt/boxen/homebrew/Cellar/bats/1.2.0: 10 files, 60K, built in 2
  40. seconds
  41. ```
  42. Run the tests with:
  43. ```bash
  44. bats hello_world_test.sh
  45. ```
  46. After the first test(s) pass, continue by commenting out or removing the
  47. `[[ $BATS_RUN_SKIPPED == true ]] || skip`
  48. annotations prepending other tests.
  49. To run all tests, including the ones with `skip` annotations, run:
  50. ```bash
  51. BATS_RUN_SKIPPED=true bats hello_world_test.sh
  52. ```
  53. ## Source
  54. This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
  55. ## External utilities
  56. `Bash` is a language to write "scripts" -- programs that can call
  57. external tools, such as
  58. [`sed`](https://www.gnu.org/software/sed/),
  59. [`awk`](https://www.gnu.org/software/gawk/),
  60. [`date`](https://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html)
  61. and even programs written in other programming languages,
  62. like [`Python`](https://www.python.org/).
  63. This track does not restrict the usage of these utilities, and as long
  64. as your solution is portable between systems and does not require
  65. installation of third party applications, feel free to use them to solve
  66. the exercise.
  67. For an extra challenge, if you would like to have a better understanding
  68. of the language, try to re-implement the solution in pure `Bash`,
  69. without using any external tools. Note that there are some types of
  70. problems that bash cannot solve, such as performing floating point
  71. arithmetic and manipulating dates: for those, you must call out to an
  72. external tool.
  73. ## Submitting Incomplete Solutions
  74. It's possible to submit an incomplete solution so you can see how others
  75. have completed the exercise.