1. Write the shell script, calculate 1-100 's and;
#!/bin/bashsum=0;for((i=0;i<=100$sum$i ))}echo$sum
2) Write the shell script, ask to enter a number, and then calculate from 1 to the input number and, if the input number is less than 1, then re-enter until the correct number is entered;
#!/bin/bashNumsave=0Read-P"Please input your number:"Num while true; DoifTest$num -lt 0; Then Read-P"Please again:"NumElse Breakfi Done for((i=0; i<=$num(i++)) {numsave=$ ($numsave+$i))}Echo $numsave
3) write the shell program to backup and restore the given directory as required.
Function:
Select 1 to back up the input directory as:/tmp
Select 2 to enable recovery of the backup directory to the current directory
Select 3, Exit
Requirements are implemented with functions:
Backup (): Implementation of directory backups, generating. tar.gz files
Restore (): Implementing a directory Recovery
TestDir (): To determine the name of the input directory, if the directory name does not exist, give an error message.
#!/bin/bashDir= $#ls-ld./$dirBackup() {tar-cvf/tmp/$dir. Tar./$dir}Restore() {tar-xvf/tmp/$dir./$dir}TestDir(){ifTest!- D $dir; ThenEcho "This isn ' t dir"#exit 0fi}testdir while true; DoSelect optinch ' BackUp Dir ' ' Restore Dir ' ' Exit '; Do Case $opt inch ' BackUp Dir ')#there isn ' tbackup;;' Restore Dir ') restore;; *)Exit 0;;Esac Done Done
Shell script Programming