This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# while.sh | |
again="yes" | |
while [ "$again" = "yes" ] | |
do | |
echo "Please enter a name:" | |
read name # !!! | |
echo "The name you entered is ${name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while [ condition ] | |
do | |
# an action, while condition is true | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in array | |
do | |
# an action, i on every iteration is getting | |
# the next value from array | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -f "$1" ]] | |
then | |
echo "Removing file ${1}" | |
rm "$1" | |
elif [[ -d "$1" ]] | |
then | |
echo "Removing dir ${1}" | |
rm -r "$1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ condition ]] | |
then | |
# action, if condition is true | |
else | |
# action, if condition is false | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! # denial of boolean expression | |
&& # boolean "and" | |
|| # boolean "or" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 |