for variable in list;
Loop body
Done
How to generate a list;
{1..100}
SEQ [Start number] [step] end value;
#!/bin/bash
lines= ' cat/etc/passwd |wc-l '
For i in ' seq 1 $lines ';
Do
User= ' cut-d:-f1/etc/passwd | head-$i | Tail-1 '
echo "Hello: $user"
Done
Output shell for bash users
#!/bin/bash
lines= ' cat/etc/passwd |wc-l '
For i in ' seq 1 $lines ';
Do
#user = ' cut-d:-f1/etc/passwd '
User= ' cut-d:-f1/etc/passwd | head-$i | Tail-1 '
Shell= ' cut-d:-f7/etc/passwd | head-$i | Tail-1 '
If grep ' \<bash\> ' $shell &>/tmp/out.txt; then
echo "Hello: $user, your shel: $shell"
Fi
Done
Add Delete 10 users
#!/bin/bash
#
if [= = Add]&>/tmp/out.txt; then
For i in {1..10};d o
Useradd $i
Done
echo "Useradd Finish"
elif [= = del]&>/tmp/out.txt; then
For i in {1..10};d o
Userdel-r $i
Done
echo "Userdell Finish"
Else
echo "Please use Add or del"
Fi
Linux Learning record-for