From 33e1323a4cb2e6606679bf567d1791af70a1cdde Mon Sep 17 00:00:00 2001 From: waldek Date: Tue, 14 Jun 2022 14:41:28 +0200 Subject: [PATCH] adds some bash 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 039bba2..e038315 100644 --- a/advanced/learning_bash_scripting.md +++ b/advanced/learning_bash_scripting.md @@ -1147,6 +1147,34 @@ For example, if the input file is a `tar.gz` file, the program will automaticall [hint](https://www.shellscript.sh/eg/directories/) +# Coding challenge - Compare and move + +Compare [these](../assets/) files from `one` directory with `second` directory and if they exist in the second directory, copy them to a `third` directory. + + +
+ +Spoiler warning! + +```bash +dir1=directory1 +dir2=directory2 +dir3=directory3 +v=v # change to v= to make it quieter +shopt -s globstar +mkdir -p$v "$dir3" +for f1 in "$dir1"/*.dll; do + for f2 in "$dir2"/**/"${f1##*/}"; do + if [[ -f "$f2" ]]; then + cp ${v:+-v} "$f1" "$dir3/" + break + fi + done +done +``` + +
+ # Coding challenge - Guess the number Can you make me a small guessing game like the one below?