timer1

Fullscreen mode

Just press »F« on your keyboard to show your presentation in fullscreen mode. Press the »ESC« key to exit fullscreen mode.

Overview mode

Press "Esc" or "o" keys to toggle the overview mode on and off. While you're in this mode, you can still navigate between slides, as if you were at 1,000 feet above your presentation.


Unix/Linux


Lesson 6

Author: Egoshkin Danila Igorevich

Plan

  1. UX/UI (Stepanova N.I.)
  2. TUI (CLI)
  3. Bash scripts
  4. GUI
  5. Zenity

UX/UI (Stepanova N.I.)

Dnipro Companies:


https://alef-estate.com/ru/

TUI (CLI)

TUI - Text user interface
CLI - Command line interface

ASCII Art


⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⣠⡄⠄⠄⠄⠄⠄⠄⢠⣄⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⢀⣴⣾⣿⣿⣿⣿⣶⣶⣶⣶⣶⣶⣿⣿⣿⣿⣷⣦⡀⠄⠄⠄⠄⠄
⠄⠄⠄⠄⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠄⠄⠄⠄
⠄⠄⠄⠄⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⠄⠄⠄⠄
⠄⠄⠄⣼⣿⣿⣿⣿⣿⡿⠿⠿⣿⣿⣿⣿⣿⣿⠿⠿⢿⣿⣿⣿⣿⣿⣧⠄⠄⠄
⠄⠄⢠⣿⣿⣿⣿⣿⡟⠄⠄⠄⠈⣿⣿⣿⣿⠁⠄⠄⠄⢹⣿⣿⣿⣿⣿⡄⠄⠄
⠄⠄⢸⣿⣿⣿⣿⣿⣇⠄⠄⠄⠄⣿⣿⣿⣿⠄⠄⠄⠄⣰⣿⣿⣿⣿⣿⡇⠄⠄
⠄⠄⢸⣿⣿⣿⣿⣿⣿⣶⣤⣴⣾⣿⣿⣿⣿⣷⣦⣤⣶⣿⣿⣿⣿⣿⣿⣷⠄⠄
⠄⠄⢸⣿⣿⣿⣿⣿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⣿⣿⣿⣿⣿⡟⠄⠄
⠄⠄⠄⠙⠻⢿⣿⣿⣷⡤⠈⠉⠉⠛⠛⠛⠛⠉⠉⠁⢤⣾⣿⣿⡿⠟⠉⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠈⠉⠻⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠟⠋⠁⠄⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄
https://www.twitchquotes.com/copypastas/ascii-art
https://knightdanila.github.io/HuskyAsciiVision/
https://en.wikipedia.org/wiki/ASCII_art

ANSI art

TUI Now


Text-based game - Text Novels
Console in Portals
Console in Minecraft
Console in intellij
Text-based game - Text Novels Roadwarden
Movie: Big 1988 (Tom Hanks)

Movie: Big 1988 (Tom Hanks)

Movie: Big 1988 (Tom Hanks)

Win:Far and Lin:Midnight Commander

TUI

Bash scripts

Path?

                            #!/bin/bash
                            #!/bin/bin/bash
                            #!/usr/bin/env bash
                            #!/root/bash
                        

Bash scripts


                            #!/bin/bash
                            # This is a comment
                            pwd
                            whoami | Win: hostname %username%
                        

Reminder: chmod +x ./myscript

Bash scripts


                            #!/bin/bash
                            echo "$1 + $2 = $(($1 + $2))"
                        

Bash scripts


                        T1='foo'
                        T2='bar'
                        if [[ $T1 == "$T2" ]] 
                        then
                          echo 'условие выполняется'
                        else
                          echo 'условие не выполняется'
                        fi
                        

Bash scripts


                        for i in "Номер "{1..10}
                        do
                            echo "$i"
                        done
                        

Bash scripts

Cycle


                        for i in {1..10}
                        do
                            echo "Hi, there ""$i"
                        done
                        

Bash scripts


                        declare -a arrAnimals
                        arrAnimals=(dog elephant horse cow fox koala turtle)
                        # Displaying the content of the array:
                        echo "${arrAnimals[@]}"
                        # Add a new element to the end of the arrAnimals array: "pig"
                        arrAnimals+=(pig)
                        # And again we show the contents of the array:
                        echo "${arrAnimals[@]}"
                        

Zenity GUI


                            sudo apt-get install zenity
                        

                            zenity --info --title “Check zenity”
                        

                            chmod +x ./script.sh
                        

Ex1 User Name


                           #!/bin/bash 

                            name=$(zenity --forms --title="Create a user" --text="Enter your data" \ 
                            --add-entry="First Name" \ 
                            --add-entry="Last Name") 

                            if [ $? = 0 ]; then  

                                echo "User full name: $name." 

                                zenity --info --title="User full name" --text="$name" 

                            else 

                                echo "User hasn't enetered a name and pressed cancel." 

                            fi 
                    

Ex2


                           zenity --question --text "Do you want to add new contact?";echo $?
                           zenity --forms --title="Add new Friend" --text="Enter information about your friend" \
                           --separator=" , " --add-entry="First name" --add-entry="Last name" \
                           --add-entry="Email" --add-calendar="Birthday"
                    

Ex3


                        #/bin/bash 
                        value1=$(zenity --entry --title "Entry of a value" --text "Enter a value") #вводимо якись текст 

                        value2=$(zenity --color-selection --title "Select a color") #обираємо колір 

                        (zenity --info --text "you entered $value1 value and chosen $value2 color") #створюємо вікно виводу значень 
                    

Ex4


                        num=$(zenity --forms --title="Add Friend" \
                        --text="Enter information about your friend." \
                        --add-entry="First Name" \
                        --add-entry="Family Name" \
                        --add-calendar="Birthday " --forms-date-format='%Y-%m-%d' )

                        fname=$(echo $num | awk 'BEGIN {FS="|"} {print $1}')
                        sname=$(echo $num | awk 'BEGIN {FS="|"} {print $2}')
                        bir=$(echo $num | awk 'BEGIN {FS="|"} {print $3}')

                        result=$(zenity --info \
                        --title="Welcome" \
                        --text="Your friend: $fname $sname ,date: $bir " )
                    

Ex5 Сафиюлин Александр

https://github.com/Chupakabra0

                            #!/bin/bash
                            file_name=$(zenity --file-selection --title="Choose file (Choose your destiny)")
                            properties=$(stat $file_name)

                            result=$(zenity --info --title="File properties" --width=300 --height=150 \
                            --text="File properties:\n $properties" --ok-label="Ok")
                    

Ex{} Евгений Булгаков


                    #!/bin/bash 

                    function FORM() { 
                    local form=$(zenity --forms --title="Заполните форму" \ 
                    --text="Сбор информации" \ 
                    --separator="," \ 
                    --ok-label=Отправить \ 
                    --cancel-label=Закрыть \ 
                    --add-entry="Имя:" \ 
                    --add-entry="Фамилия:" \ 
                    --add-entry="E-mail:" \ 
                    --add-password="Ваш пароль (минимум 5-nь символов)" \ 
                    --add-password="Повторите пароль" \ 
                    --add-list="Ваше любимое Домашнее животное" --list-values="Кот|Собака|Попугай|Рыбы" ) 

                    local name=$( echo $form | awk -F ',' '{print $1}' ) 
                    local lastname=$( echo $form | awk -F ',' '{print $2}' ) 
                    local email=$( echo $form | awk -F ',' '{print $3}' ) 
                    local password1=$( echo $form | awk -F ',' '{print $4}' ) 
                    local password2=$( echo $form | awk -F ',' '{print $5}' ) 
                    local pets=$( echo $form | awk -F ',' '{print $6}' ) 

                    if [[ ${#name} == 0 ]]; then 
                        zenity --warning --text "Пожалуйста, заполните поле имени" 
                        FORM 
                        return 
                    fi 

                    if [[ ${#lastname} == 0 ]]; then 
                        zenity --warning --text "Пожалуйста, заполните поле фамилии" 
                        FORM 
                        return 
                    fi 

                    if [[ ${#email} == 0 ]]; then 
                        zenity --warning --text "Пожалуйста, заполните поле e-mail'а" 
                        FORM
                        return 
                    fi 

                    if [[ $password1 == $password2 ]]; then 

                    if [[ ${#password1} == 0 ]]; then 
                        zenity --warning --text "Пожалуйста, заполните поле пароля" 
                        FORM 
                        return 
                    fi

                    if [[ ${#password1} < 5 ]]; then 
                        zenity --warning --text "В Вашем пароле менее 5-ти символов" 
                        FORM 
                        return 
                    fi 

                    else 
                        zenity --warning --text "Ваши пароли не совпадают" 
                        FORM 
                        return 
                    fi 

                    percent=0; 

                    for num in 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%; do 

                    echo $percent 
                    echo "# $num" 
                    percent=$(($percent + 10)); 
                    sleep 1 

                    done | zenity --progress --title='Загрузка...' --no-cancel --auto-close --percentage=0    --width=80 --height=50 

                    zenity --info --width=350 --height=150 --text "$lastname $name, мы знаем о Вас всё. 

                    Ваш email - $email 

                    Ваш пароль - $password1 

                    Ваше любимое дом. жив. - $pets" 
                    } 

                    FORM 
                    

Ex - Vlad Polustruyev


                            #/bin/bash

                            # Series or Parallel
                            # последовательно или параллельно
                            Condition1="Series" # последовательно
                            Condition2="Parallel" # параллельно

                            form=$(zenity --forms --title="Solve capacity" \
                                    --text="Enter V and A of Accum" --separator="," \
                                    --add-entry="Voltage: " \
                                    --add-entry="Amper: " \
                                    --add-entry="quantity: " \
                                    --add-list="Path of Electical chain" \
                                    --list-values="${Condition1}|${Condition2}")

                            V=$(echo $form | awk 'BEGIN {FS=","}{print $1}')
                            A=$(echo $form | awk 'BEGIN {FS=","}{print $2}')
                            Q=$(echo $form | awk 'BEGIN {FS=","}{print $3}')
                            P=$(echo $form | awk 'BEGIN {FS=","}{print $4}')

                            echo $P, $V, $A, $Q

                            if [[ $P == $Condition1 ]]; then
                                    echo ${Condition1}
                                    inf=$(echo $V*$Q | bc)
                                    result=$(zenity --info --title="Information about accum" --text="Volt = $inf, Amper = $A, Quant = $Q, Path = $P")
                            fi

                            if [[ $P == $Condition2 ]]; then
                                    echo ${Condition2}
                                    inf=$(echo $A*$Q | bc)
                                    result=$(zenity --info --title="Information about accum" --text="Volt = $V, Amper = $inf, Quant = $Q, Path = $P")
                            fi
                    

Ex - Yevgeniy Levchenko


                        #!/usr/bin/env bash 

                        while : ; do 
                            ageCalc=$(zenity --forms --title="Age Calculator" \ 
                               --add-entry="First Name" \ 
                               --add-entry="Last Name" \ 
                               --add-calendar="Birth Date: ") 

                            if [[ "$?" != "0" ]] 
                            then 
                                break 
                            fi 

                            firstName="$(echo "$ageCalc"| cut -d '|' -f 1)" 
                            lastName="$(echo "$ageCalc"| cut -d '|' -f 2)" 
                            birthDateStr="$(echo "$ageCalc"| cut -d '|' -f 3)" 
                            epoch_time=$(date -j -f '%d.%m.%Y' "$birthDateStr" +'%s') 
                            birthDate=$(date -j -r "$epoch_time" +%d.%m.%Y) 

                            birthDay="$(echo "$birthDate"| cut -d '.' -f 1)" 
                            birthMonth="$(echo "$birthDate"| cut -d '.' -f 2)" 
                            birthYear="$(echo "$birthDate"| cut -d '.' -f 3)" 

                            birthDay=$((10#$birthDay)) 
                            birthMonth=$((10#$birthMonth)) 

                            currentDate=$(date +%d.%m.%Y) 
                            currentDay="$(echo "$currentDate"| cut -d '.' -f 1)" 
                            currentMonth="$(echo "$currentDate"| cut -d '.' -f 2)" 
                            currentYear="$(echo "$currentDate"| cut -d '.' -f 3)" 

                            currentDay=$((10#$currentDay)) 
                            currentMonth=$((10#$currentMonth)) 

                            month=(31 28 31 30 31 30 31 31 30 31 30 31) 

                            if [ $birthDay -gt $currentDay ] 
                            then 
                                currentDay=$((10#$currentDay + month[$birthMonth - 1])) 
                                currentMonth=$((currentMonth - 1)) 
                            fi 

                            if [ $birthMonth -gt $currentMonth ] 
                            then 
                                currentYear=$(($currentYear - 1)) 
                                currentMonth=$(($currentMonth + 12)) 
                            fi 

                            calculatedDays=$((currentDay - birthDay)) 
                            calculatedMonths=$((currentMonth - birthMonth)) 
                            calculatedYears=$((currentYear - birthYear)) 

                            name="$firstName $lastName" 
                            if [ -z $firstName ] && [ -z $lastName ] 
                            then 
                                name="stranger" 
                            fi 

                            if [ 0 -gt $calculatedYears ] 
                            then 
                                zenity --info --text="Hi, ${name}. You have not born yet!" --width=500 
                            else 
                                zenity --info --text="Hi, ${name}. Your present age is ${calculatedYears:-0} years, ${calculatedMonths:-0} months, ${calculatedDays:-0} days" --width=500 
                            fi 

                        done 
                    

Links:

https://ryanstutorials.net/bash-scripting-tutorial/bash-input.php
https://linuxhint.com/prompt-for-input-bash/
Thanks for your attention :)