Linux shell scripting

Source: Internet
Author: User

Linux shell scripting:
1. Program Structure Exercise: Write a script, given a positive integer, to calculate the sum of all digits of this number.
For example, if the program is given input 123, it should return 1+2+3=6.

2. Program Structure Exercise: Write a script, given a positive integer, to output this number in reverse order.
For example: program input 123, then should output 321.

3.Linux Command +shell Programming: Write a program to achieve the function of timing file backup.
Requirements:
1. Back up all files in a directory
2. Compressing the backup file
3. Generate a reasonable log file

GUI (libnotify-bin) programming under 4.Shell
http://blog.mpathirage.com/2009/09/12/using-libnotify-in-ubuntu-9-04/
Requirements:
Implement the Timer reminder function, set the prompt time and reminder content by command line parameter

5.Shell Text processing capabilities (SED and awk)
1. Open sname and Smark two files to view the contents of the file.
2. The student name (cut) is extracted from the sname and is displayed as follows:
Zhangsan
Lisi
Wangwu
Maliu
3. Merge the contents of the two files (join) with the output as follows:
Zhangsan 56
78 Lisi
98 Wangwu
87 Maliu
4. Lowercase letters converted to uppercase letters (TR)
5. View the inventory file, filter to the middle row, and get the data for the first and third rows. The effect is as follows:
Cacke 10
Pen 12
Floppy 5


6. View the Teaormilk file and replace the teas in each row with milk. (SED) results are as follows:

India ' s milk is good.
Milk red-lable is good.
Milk is better than the coffee.
7. View the Personame file and output only one row of data (Uniq). The results are as follows:
Hello I am Vivek
12333
Welcome
To
Sai Computer Academy a ' bad.
What I still remember that name
Oaky!how is U, luser
What still I remember that name
8. View the Demo-file file, requiring that only rows containing too (grep) be printed on the line. The results are as follows:
Cartoons is good
Especially toon like Tom (cat)
I too
Please master the program to me to write out, will be a few to write a few, thank you.


Best Answer first question
#!/bin/bash
declare-i a=$1
declare-i sum=0
While ["$a"-ne "0"]
do
sum= $sum +$ A%10
a= $a/10
Done
echo "The result is $sum"
second question
#!/bin/bash
Declare-i a=$1
While [$a-ne 0]

Do
Echo-n "$ (($a%10))"
A= $a/10
Done
Echo
Third question
The script is named backupdaily.sh
Add a line to the/etc/crontab
0 2 * * * Root ~/backup/backupdaily.sh
#!/bin/bash
day= ' Date +%y%m%d '
Tar-czf ~/backup/"$day". tar.gz ~/anydir
echo "$day: Tar-czf ~/backup/$day. tar.gz ~/anydir" >> ~/backup/backuplog
Question Fourth
Not used before, tried, manpage in the few parameters
#例如提示 "message" lasts for three seconds:
#notify-send "message"-t 3000

Question Fifth
Brother, you're not giving sname and Smark. format, field position I'm just guessing.
1. #cat sname; Cat Smark
2. #cat sname | Cut-d '-F 2
3. #join-1 1 sname-2 1 Smark
4. #cat sname Smark | TR "[A-Z]" "[A-z]"
5 #cat Inventory | Cut-d '-F 1,3
6#cat Teaormilk | Sed ' s/tea/milk/g '
7#cat Personame | Sort | Uniq-u
8#cat Demo-file | grep "Too"

Linux shell scripting

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.