Browse Source

feat(skip-lines): add subject, test and solution for the exercise skip-line

pull/1649/head
miguel 2 years ago committed by MSilva95
parent
commit
4b02c825b7
  1. 11
      sh/tests/skip-lines_test.sh
  2. 3
      sh/tests/solutions/skip-lines.sh
  3. 47
      subjects/skip-lines/README.md

11
sh/tests/skip-lines_test.sh

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Unofficial Bash Strict Mode
set -euo pipefail
IFS='
'
submitted=$(bash student/skip-lines.sh)
expected=$(bash solutions/skip-lines.sh)
diff <(echo "$submitted") <(echo "$expected")

3
sh/tests/solutions/skip-lines.sh

@ -0,0 +1,3 @@
#!/usr/bin/env bash
ls -l | sed -n 'n;p'

47
subjects/skip-lines/README.md

@ -0,0 +1,47 @@
## Skip lines
### Instructions
Write a command line in a `skip-lines.sh` file that prints the result of a `ls -l` skipping 1 line out of 2, starting with the **first** one.
Example:
```console
User-> ls -l
drwxr-xr-x 16 User User 4096 nov 11 10:55 Desktop
drwxr-xr-x 22 User User 4096 nov 4 10:02 Documents
drwxr-xr-x 6 User User 4096 nov 11 10:40 Downloads
drwxr-xr-x 2 User User 4096 mar 31 2022 Music
drwxr-xr-x 2 User User 4096 set 29 10:34 Pictures
drwxr-xr-x 2 User User 4096 nov 23 2021 Public
```
What we want your script to do is:
```console
drwxr-xr-x 16 User User 4096 nov 11 10:55 Desktop
drwxr-xr-x 6 User User 4096 nov 11 10:40 Downloads
drwxr-xr-x 2 User User 4096 set 29 10:34 Pictures
```
**Tips:**
Here are some Commands that can help you:
- `sed`. Edit text in a scriptable manner. You can see also: awk. [For more information](https://www.gnu.org/software/sed/manual/sed.html).
- Print just a first line to stdout:
`{{command}} | sed -n '1p'`
```console
User-> cat file
AIX
Solaris
Unix
Linux
HPUX
User-> sed -n '1p' file
AIX
```
Use man to see how `awk` or `sed` works, they can do the job.
Loading…
Cancel
Save