Skip to content

Instantly share code, notes, and snippets.

@jybaek
Last active January 12, 2016 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jybaek/a5275a0b29a5534aa9c3 to your computer and use it in GitHub Desktop.
Save jybaek/a5275a0b29a5534aa9c3 to your computer and use it in GitHub Desktop.
stackoverflow QA
cur=$(date +%m) # Need not be described
next6=$(printf %02d $(echo $(($cur+6))%12 | bc))
# 1. $(($cur+6)) is same 'expr' command. result is 7
# 2. echo 7%12 | bc result '7' (remainder)
# 3. printf %02d => 01, 02, 03 ...
# 4. $next6 => current month + 6
# 5. My mistake, if $next6 is 0 => change 1 (if [ $next6 == 0 ];then next6=1;fi)
# 6. END
next6_y=$(echo $(($cur+6))/12 + $(date +%Y) | bc)
# 1. $(($cur+6)) is same 'expr' command. result is 7
# 2. echo 7/12 | bc result '0' (quotient)
# 3. $(date +%Y) ==> 2016
# 4. 0 + 2016 | bc ==> 2016
# 5. END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment