more scripting

This commit is contained in:
waldek 2022-05-23 16:51:00 +02:00
parent 83d38d2105
commit 4719e5d451
2 changed files with 61 additions and 1 deletions

View File

@ -732,7 +732,6 @@ waldek@debian:~$ which true
/usr/bin/true /usr/bin/true
waldek@debian:~$ which false waldek@debian:~$ which false
/usr/bin/false /usr/bin/false
waldek@debian:~$ man true
waldek@debian:~$ whatis true waldek@debian:~$ whatis true
true (1) - do nothing, successfully true (1) - do nothing, successfully
waldek@debian:~$ whatis false waldek@debian:~$ whatis false
@ -765,6 +764,8 @@ waldek@debian:~$ echo $?
waldek@debian:~$ test -a does_not_exist waldek@debian:~$ test -a does_not_exist
waldek@debian:~$ echo $? waldek@debian:~$ echo $?
1 1
waldek@debian:~$ test ! -a does_not_exist; echo $?
0
waldek@debian:~$ waldek@debian:~$
``` ```
@ -1108,6 +1109,10 @@ whale says: I'm an animal...
waldek@debian:~$ waldek@debian:~$
``` ```
## `break` and `continue`
TODO
# Coding challenge - pipe or argument plus action! # Coding challenge - pipe or argument plus action!
Can you expand the previous coding challenge, where you perform a conditional logic on the input of the script and actually *use* the incoming data? Can you expand the previous coding challenge, where you perform a conditional logic on the input of the script and actually *use* the incoming data?
@ -1118,6 +1123,52 @@ Rename all files from [this](../assets/simple_sort_01.tar.gz) file with an prefi
Can you give the files that start with an **uppercase** letter a different pre or postfix? Can you give the files that start with an **uppercase** letter a different pre or postfix?
Can you move the files with lowercase into a different folder? Can you move the files with lowercase into a different folder?
# Coding challenge - Guess the number
Can you make me a small guessing game like the one below?
```
waldek@debian:~$ ./test.sh
I have a number in mind between 0 and 100
your quess: 10
my number is smaller...
your quess: 5
my number is bigger...
your quess: helloworld
I don't understand you...
your quess: 6
disco! I had 6 in mind...
waldek@debian:~$
```
<details>
<summary>Spoiler warning!</summary>
```bash
#!/bin/bash
difficulty=100
computernumber=$(( "$RANDOM % $difficulty"))
echo "I have a number in mind between 0 and $difficulty"
while true; do
read -p "your quess: " usernumber
if [ $usernumber -lt $computernumber ] 2> /dev/null; then
echo "my number is bigger..."
elif [ $usernumber -gt $computernumber ] 2> /dev/null; then
echo "my number is smaller..."
elif [ $usernumber -eq $computernumber ] 2> /dev/null; then
echo "disco! I had $computernumber in mind..."
break
else
echo "I don't understand you..."
fi
done
```
</details>
# Functions - Reuse code to make life easier. # Functions - Reuse code to make life easier.
## defining a function ## defining a function
@ -1133,10 +1184,15 @@ Can you move the files with lowercase into a different folder?
# User Interface - Make your scripts user friendly. # User Interface - Make your scripts user friendly.
* `case` for command line arguments * `case` for command line arguments
* `select` for small menu's
* [dialog tutorial](https://www.linuxjournal.com/article/2807) * [dialog tutorial](https://www.linuxjournal.com/article/2807)
* [better dialog tutorial](https://linuxcommand.org/lc3_adv_dialog.php) * [better dialog tutorial](https://linuxcommand.org/lc3_adv_dialog.php)
* [Ryan's tutorials](https://ryanstutorials.net/bash-scripting-tutorial/bash-user-interfaces.php) * [Ryan's tutorials](https://ryanstutorials.net/bash-scripting-tutorial/bash-user-interfaces.php)
# Arrays in `bash`
TODO
## Python ## Python
[This](https://gitea.86thumbs.net/waldek/python_course_doc) repository has a twenty day course to learn python written by me. [This](https://gitea.86thumbs.net/waldek/python_course_doc) repository has a twenty day course to learn python written by me.

View File

@ -26,6 +26,7 @@ TODO
TODO TODO
# Shell completion # Shell completion
TODO TODO
@ -42,3 +43,6 @@ TODO
TODO TODO
# `xxh`
TODO