1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/bash
#Version:0.1
#Author:lovelace
#calculaion and from 1 to 10
#difine two variable
declare
-i i=1
declare
-i
sum
=0
#use while to loop
while
((i<=10));
do
let
sum
+=i
let
++i
done
#print the result
echo
$
sum
|
1
2
|
[root@lovelace
while
]
# ./while1.sh
55
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#!/bin/bash
#Vsersion:0,1
#Author:lovelace
#Pragram:This pragram is show user who use bash
#use while read files
while
read
line;
do
#filter out the user who use bash
Bashuser=`
echo
$line |
awk
-F:
'{print $1,$NF}'
|
grep
'bash'
|
awk
'{print $1}'
`
#jugement Bashuser is null or not and print the user who use bash shell
if
[ ! -z $Bashuser ];
then
echo
"$Bashuser use bash shell."
fi
done
<
"/etc/passwd"
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@lovelace
while
]
# ./readpasswd.sh
root use
bash
shell.
nick use
bash
shell.
kale use
bash
shell.
user2 use
bash
shell.
user3 use
bash
shell.
user4 use
bash
shell.
user5 use
bash
shell.
user6 use
bash
shell.
user7 use
bash
shell.
user8 use
bash
shell.
user9 use
bash
shell.
user10 use
bash
shell.
mark use
bash
shell.
lovelace use
bash
shell.
lovetest use
bash
shell.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@lovelace
while
]
# cat catwhile.sh
#!/bin/bash
#Version:0.1
#Author:lovelace
#Pragram:This pragram is show user who use bash
#use pipe transparent data to {}
cat
/etc/passwd
| {
while
read
line;
do
#use if statement jugement bash shell user and print it
if
[
"`echo $line | awk -F: '{print $NF}'`"
==
"/bin/bash"
];
then
Bashuser=`
echo
$line |
awk
-F:
'{print $1}'
`
echo
"$Bashuser use bash shell."
fi
done
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@lovelace
while
]
# ./catwhile.sh
root use
bash
shell.
nick use
bash
shell.
kale use
bash
shell.
user2 use
bash
shell.
user3 use
bash
shell.
user4 use
bash
shell.
user5 use
bash
shell.
user6 use
bash
shell.
user7 use
bash
shell.
user8 use
bash
shell.
user9 use
bash
shell.
user10 use
bash
shell.
mark use
bash
shell.
lovelace use
bash
shell.
lovetest use
bash
shell.
|
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
|
#!/bin/bash
#Pragram:This pragram is check the number you input
#Set the variable is not defined are not allowed to shopt -s -o nounset
#usedifine variale
declare
-i num
declare
-i i
declare
-i x
while
[[ $num -lt 2 ]]
do
read
-p
"please input a number greater than 2:"
num
done
i=2
echo
-n $num
'='
while
((num>=i))
do
x=0
tmp=num%i
while
[[ $tmp -
eq
0 ]]
do
((num/=i))
((x++))
tmp=num%i
done
if
[[ $x -gt 0 ]];
then
echo
-n $i
[ $x -gt 1 ] &&
echo
-n
'^'
$x
[ $num -gt 1 ] &&
echo
-n
' * '
fi
((i>=3?i+=2:i++))
done
echo
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@lovelace
while
]
# ./prem.sh
please input a number big 2:3
3 =3
[root@lovelace
while
]
# ./prem.sh
please input a number big 2:-23
please input a number big 2:nick
.
/prem
.sh: line 11: nick: unbound variable
[root@lovelace
while
]
# ./prem.sh
please input a number big 2:4
4 =2^2
[root@lovelace
while
]
# ./prem.sh
please input a number big 2:9
9 =3^2
|