azet / community_bash_style_guide

Community Bash Style Guide: writing useful and modern bash scripts, seriously.
Creative Commons Attribution 4.0 International
298 stars 37 forks source link

Arrays start index with 0, awk with 1 #14

Closed kallies closed 6 years ago

kallies commented 7 years ago

Fix index count issue.

kallies commented 7 years ago

An independent change would be do add a echo in front:

- ${listofthings} | awk '{ print $3 }' # get the third item
+ echo ${listofthings} | awk '{ print $3 }' # get the third item
- ${listofthings[2]}             # get the third item (start counting from 0)
+ echo ${listofthings[2]}             # get the third item (start counting from 0