mirror of https://github.com/01-edu/public.git
Zouhair AMAZZAL
2 years ago
committed by
Zouhair AMAZZAL
12 changed files with 80 additions and 0 deletions
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash |
||||
|
||||
# Unofficial Bash Strict Mode |
||||
set -euo pipefail |
||||
IFS=' |
||||
' |
||||
|
||||
script_dirS=$(cd -P "$(dirname "$BASH_SOURCE")" &>/dev/null && pwd) |
||||
|
||||
challenge() { |
||||
submitted=$(cd "$1" && bash "$script_dirS"/student/find-files-extension.sh) |
||||
expected=$(cd "$1" && bash "$script_dirS"/solutions/find-files-extension.sh) |
||||
|
||||
diff <(echo "$submitted") <(echo "$expected") |
||||
} |
||||
|
||||
challenge find-files-extension/folder1 |
||||
challenge find-files-extension/folder2 |
@ -0,0 +1,3 @@
|
||||
#!/bin/bash |
||||
|
||||
find . -iregex '.*\.\(txt\)' -exec basename {} \; | cut -d "." -f 1 |
@ -0,0 +1,59 @@
|
||||
## find-files-extension |
||||
|
||||
### Instructions |
||||
|
||||
Create a file `find-files-extension.sh`, which will look, from the current directory and its sub-folders for: |
||||
|
||||
all the files with `.txt` extension. |
||||
|
||||
That command will only show the name of the files without the extension `.txt`. |
||||
|
||||
- You can use this for testing: https://assets.01-edu.org/devops-branch/find-files-extension-example.zip |
||||
|
||||
- What to use : `find` |
||||
|
||||
- The output should be exactly like the example bellow but with the expected name |
||||
|
||||
```console |
||||
$pwd |
||||
<..>/find-files-extension-example |
||||
$./find-files-extension.sh | cat -e |
||||
qwep$ |
||||
pq1$ |
||||
zzzz$ |
||||
ziko$ |
||||
wei$ |
||||
ek$ |
||||
$ |
||||
``` |
||||
|
||||
### Hints |
||||
|
||||
`find` command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments: |
||||
You can use REGEX in `find` command. |
||||
|
||||
```console |
||||
$find ~/ -iregex '<REGEX>' |
||||
<all files and folders in the user home that respect the specified regex> |
||||
$ |
||||
``` |
||||
REGEX for txt files: `.*\.\(txt\)` |
||||
|
||||
`cut` command is a command-line utility that allows you to cut out sections of a specified file or piped data and print the result: |
||||
|
||||
```console |
||||
$cat cut-example.txt |
||||
abc-lol |
||||
testtest-abcx |
||||
qwerty-azerty-x |
||||
$cat cut-example.txt | cut -d "-" -f 1 # cut the lines with "-" as delimiter and print the first part. |
||||
abc |
||||
testtest |
||||
qwerty |
||||
$ |
||||
``` |
||||
|
||||
May you will need to use `pipe (|)` and `&&`. |
||||
|
||||
> You have to use Man or Google to know more about commands flags, in order to solve this exercice! |
||||
> Google and Man will be your friends! |
Loading…
Reference in new issue