A few days ago in doing 2014 Ma brother Linux0214 's homework, found that in fact, the three questions in 0217 has a solution, of course, I think Ma brother than his own writing too much, so can not help but to Marco the answer to put out for their own study.
First question: Write a script that shows how many lines/etc/init.d/functions,/etc/rc.d/rc.sysinit,/etc/fstab are displayed with a for loop
#!/bin/bash
For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab;do
Linecount= ' Wc-l $fileName | Cut-d '-f1 '
echo "$fileName: $lineCount lines."
Done
or more concise:
#!/bin/bash
For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab;do
echo "$fileName: ' Wc-l $fileName | cut-d '-f1 ' lines.
Done
The writing is undoubtedly the most concise.
The second question: write a script, the previous question in the three files copied to the/tmp directory, with A For loop implementation, respectively, each file last modified time to September 15, 2011 13:27.
#!/bin/bash
For FileName In/etc/init.d/functions/etc/rc.d/rc.sysinit/etc/fstab;do
CP $fileName/tmp
Basename= ' BaseName $fileName '
TOUCH-MT 201109151327/tmp/$baseName
Done
Third question: Write a script that shows the user names and ID numbers for the 3, 7, and 11 users in/etc/passwd.
#!/bin/bash
For Lineno in 3 7 11;do
userinfo= ' Head-n $lineNo/etc/passwd | Tail-1 | cut-d:-f1,3 '
Echo-e "User: ' Echo $userInfo | cut-d:-f1 ' \nuid: ' echo $userInfo | cut-d:-f2 ' "
Done
I wrote the following, made a little change, I feel fit my style, but the main frame unchanged.
#!/bin/bash
way=/etc/passwd
For Lineno in 3 7 11;do
echo "User name: ' head-$lineNo $way | Tail-1 | cut-d:-f1 ' UserID: ' head-$lineNo $way | Tail-1 | cut-d:-f3 ' "
Done
Personal feeling, Marco's third problem is a bit cumbersome ah.
At the beginning of a few toy programme, the value of inspiration for ideas is relatively large.
2014 the answers to 2,143 questions in the Linux0217 of Ma Brothers