adds some bash ex
This commit is contained in:
parent
45cdcf0c8b
commit
33e1323a4c
|
@ -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/)
|
[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.
|
||||||
|
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
<summary>Spoiler warning!</summary>
|
||||||
|
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
# Coding challenge - Guess the number
|
# Coding challenge - Guess the number
|
||||||
|
|
||||||
Can you make me a small guessing game like the one below?
|
Can you make me a small guessing game like the one below?
|
||||||
|
|
Loading…
Reference in New Issue