Skip to content

Instantly share code, notes, and snippets.

@M1nified
Created January 31, 2020 21:49
Show Gist options
  • Save M1nified/7ea0540c0e3f1421bb7ac03340038e6a to your computer and use it in GitHub Desktop.
Save M1nified/7ea0540c0e3f1421bb7ac03340038e6a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Utworz folder o nazwie podanej przez read.
# Z folderu podanego przez pierwszy argument, skopiuj do niego wszystkie pliki o rozszerzeniu podanym przez drugi argument, mlodsze niz plik backup.time.
FOLDER_ZRODLOWY=$1
ROZSZERZENIE=$2
echo -n "Podaj nazwe folderu docelowego: "
read FOLDER_DOCELOWY
mkdir -p $FOLDER_DOCELOWY # -p = no error if existing, make parent directories as needed
echo "Copy from $FOLDER_ZRODLOWY to $FOLDER_DOCELOWY"
FILES_TO_COPY=$(find $FOLDER_ZRODLOWY/*.$ROZSZERZENIE -newer backup.time)
echo $FILES_TO_COPY
cp $FILES_TO_COPY $FOLDER_DOCELOWY
#!/bin/bash
# Utworz folder o nazwie podanej przez read.
# Z folderu bieżącego, skopiuj do niego wszystkie pliki o rozszerzeniu podanym przez pierwszy argument skryptu, mlodsze niz plik bp.t.
ROZSZERZENIE=$1
echo -n "Podaj nazwe folderu docelowego: "
read FOLDER_DOCELOWY
mkdir -p $FOLDER_DOCELOWY # -p = no error if existing, make parent directories as needed
echo "Copy from current dir to $FOLDER_DOCELOWY"
FILES_TO_COPY=$(find *.$ROZSZERZENIE -newer backup.time)
echo $FILES_TO_COPY
cp $FILES_TO_COPY $FOLDER_DOCELOWY
#!/bin/bash
echo $0
echo $1
echo $2
# false=0
# true=1
# ((false)) && echo false
# ((true)) && echo true
# ((!false)) && echo not false
# ((!true)) && echo not true
# echo "-----------"
# if [ 1 ]
# then
# echo 'true'
# fi
# if [ 0 ]
# then
# echo 'false'
# fi
# echo "-----------"
# x=''
# if [ -n $x ]
# then
# echo 'ok1'
# fi
# if [ $x ]
# then
# echo 'ok2'
# fi

Jakiego rodzaju zmienne wystepuja w skryptach i jak sa one przekazywane do innych procesów?

chuj wie

  • lokalne local nazwa_zmiennej
  • globalne

moze o to chodzi

ta druga czesc to chyba to samo co w nastepnym

Podaj i opis sposoby wprowadzania danych do skryptu

PIPE: ls | grep .x Argumenty: program.sh arg1 arg2 ...

Opisz operatory relacji (< > ...) i operatory logiczne. Podaj przyklady

https://www.geeksforgeeks.org/basic-operators-in-shell-scripting/

Relacji

  • == Operator : Double equal to operator compares the two operands. Its returns true is they are equal otherwise returns false.
  • != Operator : Not Equal to operator return true if the two operands are not equal otherwise it returns false.
  • <Operator : Less than operator returns true if first operand is lees than second operand otherwse returns false.
  • <= Operator : Less than or equal to operator returns true if first operand is less than or equal to second operand otherwise returns false
  • >Operator : Greater than operator return true if the first operand is greater than the second operand otherwise return false.
  • >= Operator : Greater than or equal to operator returns true if first operand is greater than or equal to second operand otherwise returns false

Arytmetyczne

  • Addition (+): Binary operation used to add two operands.
  • Subtraction (-): Binary operation used to subtract two operands.
  • Multiplication (*) :Binary operation used to multiply two operands.
  • Division (/) :Binary operation used to divide two operands.
  • Modulus (%) :Binary operation used to find remainder of two operands.
  • Increment Operator (++) : Uniary operator used to increase the value of operand by one.
  • Decrement Operator () : Uniary operator used to decrease the value of a operand by one

Logiczne

  • Logical AND (&&) : This is a binary operator, which returns true if both the operands are true otherwise returns false.
  • Logical OR (||) : This is a binary operator, which returns true is either of the operand is true or both the operands are true and returns false if none of then is false.
  • Not Equal to (!) : This is a uninary operator which returns true if the operand is false and returns false if the operand is true.

Opisz znane testy zmiennych lancuchowych (napisow). Podaj jakie wartosci zmiannych odpowiadaja true, a jakie false.

#!/bin/bash

false=0
true=1

((false)) && echo false
((true)) && echo true
((!false)) && echo not false
((!true)) && echo not true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment