From b9bd04bb1e38d726f8358c79899c93306e757743 Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 11 Jul 2022 11:50:00 +0200 Subject: [PATCH] adds new birthday ex --- advanced/learning_bash_scripting.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/advanced/learning_bash_scripting.md b/advanced/learning_bash_scripting.md index 881d11b..c81bb08 100644 --- a/advanced/learning_bash_scripting.md +++ b/advanced/learning_bash_scripting.md @@ -454,6 +454,34 @@ echo "or may I call you $first?" It is worth discovering what happens when you supply too many or to little values. Please try this out! +# Coding challenge - Birthday **day** + +Write me `bash` program that asks for your date of birth and prints the day of the week that was. +Like the output below. + +``` +waldek@server:~$ bash birthday.sh +what is your birthday (day month year)? 07 10 1986 +you where born on a Tuesday +``` + +
+Spoiler warning! + +```bash +#!/bin/bash + +read -p "what is your date of birth? (day month year) " day month year + +day_of_the_week=$(date +%A -d "$month/$day/$year") + +echo "you where born on a $day_of_the_week" +``` + +
+ + + ## With command line arguments We can create a similar behaviour but with command line arguments.