-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_scripting.sh
More file actions
120 lines (85 loc) · 1.62 KB
/
Copy pathbash_scripting.sh
File metadata and controls
120 lines (85 loc) · 1.62 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Bash scripting
$ bash --version
Common bash commands:
$ ls - List directory contents
$ echo - Prints text to the terminal windows
$ touch - Creates a file
$ mkdir - Create a directory
$ pwd - Print working directory
$ cd - Change directory
$ mv - Move or rename directory
$ less - View the contents of a text file (no edit)
$ cat - Read a file, create a file and concatenate files
$ chmod - Sets the file permissions flag on a file or folder
$ exit - Closes terminal, log you out of remote SSH access session, end execution of a shell script
$ history - List your most recent commands
$ clear - Clear your terminal window
$ cp - Copy files and directories
$ kill - Terminate stalled processes
Første script:
$ nano hello.sh
#!/bin/bash
echo "Hello World"
$ bash hello.sh
Hello World
Brug af comment:
$ nano comment.sh
#!/bin/bash
# Add two numeric value
((sum=25+35))
#Print the result
echo $sum
$ bash comment.sh
60
While loop:
$ nano while.sh
#!/bin/bash
valid=true
count=1
while [ $valid ]
do
echo $count
if [ $count -eq 5 ];
then
break
fi
((count++))
done
$ bash while.sh
1
2
3
4
5
For loop:
$ nano for.sh
#!/bin/bash
for (( counter=10; counter>0; counter-- ))
do
echo -n "$counter "
done
printf "\n"
$ bash for.sh
10 9 8 7 6 5 4 3 2 1
Get User Input:
$ nano user_input.sh
#!/bin/bash
echo "Enter Your Name"
read name
echo "Welcome $name to bash scripting"
$ bash user_input.sh
Enter Your Name
Mads
Welcome Mads to bash scripting
If statement:
$ nano simple_if.sh
#!/bin/bash
n=10
if [ $n -lt 10 ];
then
echo "It is an one digit number"
else
echo "It is a two digit number"
fi
$ bash simple_if.sh
It is a two digit number