Skip to content

Instantly share code, notes, and snippets.

View var-bin's full-sized avatar
🤙
Preprocessors do not output bad code. Bad developers do.

Vitalii Rybka var-bin

🤙
Preprocessors do not output bad code. Bad developers do.
View GitHub Profile
#!/bin/bash
# while.sh
again="yes"
while [ "$again" = "yes" ]
do
echo "Please enter a name:"
read name # !!!
echo "The name you entered is ${name}"
while [ condition ]
do
# an action, while condition is true
done
#!/bin/bash
for i in 1 2 3 4 5
do
file_name="file${i}.txt"
if [[ -e "$file_name" ]]
then
continue
fi
echo "Creating file ${file_name}"
for i in array
do
# an action, i on every iteration is getting
# the next value from array
done
#!/bin/bash
# ./case_in_esac.sh 2 1
# Creating dir 1
# ./case_in_esac.sh 1 2
# Creating file 2
if [[ "$#" -ne 2 ]]
then
echo "You should specify exactly two arguments!"
#!/bin/bash
if [[ -f "$1" ]]
then
echo "Removing file ${1}"
rm "$1"
elif [[ -d "$1" ]]
then
echo "Removing dir ${1}"
rm -r "$1"
if [[ condition ]]
then
# action, if condition is true
else
# action, if condition is false
fi
! # denial of boolean expression
&& # boolean "and"
|| # boolean "or"
-e <path> # path is exist
-f <path> # is file
-d <path> # is directory
-s <path> # file size more than 0
-x <path> # file is executable
<numbers/strings> operation <numbers/strings>
-eq, (==) # equal
-ne, (!=) # not equal
-lt, (<) # less than
-le # less than or equal
-gt, (>) # more than
-ge # more than or equal