-
Notifications
You must be signed in to change notification settings - Fork 5
/
bash-examples.sh
executable file
·79 lines (59 loc) · 1.93 KB
/
bash-examples.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /bin/bash
# Logging
function log {
echo "🟢 $1"
}
# Global and local variables
function assignGlobalVariable() {
MESSAGE="Global variables are great for function return variables in scripts since they are destroyed after the script ends."
}
function assignLocalVariable() {
local MESSAGE="Local variables exist only in the context of this function."
log "$MESSAGE"
}
function variables() {
log "$MESSAGE"
assignGlobalVariable
log "$MESSAGE"
assignLocalVariable
log "$MESSAGE"
}
# Calculation
function calculation() {
a=1
b=2
c=3
log "$a + $b + $c = $(( a+b+c ))"
}
# Numeric comparison
function numericCompare() {
a=3
b=2
c=2
[[ $a > $b ]] && log "$a is greater than $b"
[[ $b > $c ]] || log "$b is smaller or equal than $c"
}
# Create empty file in multiple sub folders
function createEmptyFileInMultipleSubfolders() {
find . -type d -path "./Targets/*/Config" -exec touch {}/Speisewagen-Shared.xcconfig \;
}
# Rename a specific file in multiple sub folders
function renameSpecificFileInMultipleSubfolders() {
# Load plugin in ZSH
autoload zmv
zmv -nW 'Targets/**/Config/*.xcconfig' 'Targets/**/Config/App-*.xcconfig'
}
# Replace the same text in a specific file in multiple sub folders
function replaceTextInSameFileOfMultipleSubfolders() {
sed -i '' 's/Shared.xcconfig/App-Shared.xcconfig/g' Targets/**/Config/App-Release.xcconfig
}
# Append text to specific files in multiple sub folders
function appendTextToSpecificFilesInMultipleSubfolders() {
find . -type f -path "./Targets/*/Config/Speisewagen*.xcconfig" -not -path "./Targets/*/Config/Speisewagen-Shared.xcconfig" -exec sh -c 'echo "#include \"Speisewagen-Shared.xcconfig\"" >> {}' \;
}
function findScriptPathIfItIsExecutedViaSymlinkOrNot() {
DIR=$(cd "$(dirname "$(readlink "$0" || echo "$0")")" && pwd)
echo $DIR
}
## -----------------------------------------------
variables