#bash #linux
Reasons why I love bash
- avaliable on almost all *NIX systems
- integrates easily with avaliable programs installed
- allows quick iteration for one off scripts
Reasons I dislike bash
- arrays (ugh)
Here I create an array and bash and loop over it. Notice the proper way to loop over an array is a syntax that is difficult to remember. You need to do this to avoid unexpected word splitting or globing. This is not needed if items in the array do not contain spaces or special characters. But you should always do this just in case!
#!/bin/bash
shopping_list=("apple", "cherry", "banana")
for item in "${shopping_list[@]}"; do
echo "List item: $item"
done
# Output:
# List item: apple
# List item: cherry
# List item: banana
Another bash example with integers
#!/bin/bash
days=(31)
echo "Number of days doubled: $((days * 2))"
# Output:
# Number of days doubled: 62