First, write a script, let the user input: 1.first name 2.last name, last displayed on the screen: Your full name is: Content
#!/bin/bashread-p "Please input your firstname:" firstnameread-p "Please input your lastname:" LASTNAMEECHO-E "your ful L name is: $firstname $lastname "
Second, the user input 2 variables, and then multiply the 2 variables, the final output multiplication results
#!/bin/bashread-p "Input first number:" Firstnuread-p "input second number:" Secnutotal=$ (($FIRSTNU * $secnu)) Echo-e "the Result of $firstnu x $SECNU is $total "
Third, use source to execute script, you can put the variable in the parent process (environment)
Iv. the user enters a filename and makes the following judgments:
-
FileName file exists, does not exist, terminates the program
-
If it exists, determine whether it is a file or a directory and enter the result
-
Determine the permissions that the current identity user has on the file/directory and output the results
#!/bin/bashecho-e "Please input a filename,this program would check the file ' s type and permission" Read-p "input a Filena Me: "filename#1. Determine if the user really has an input string test-z $filename &&echo" You must input a filename "&& exit 0#2. Determine if the file exists, Does not exist then terminates the program test! -E $filename &&echo "The filename $filename no exist" && exit 0#3. Determine file type and properties Test-f $filename && Filetype= "Regular file" test-d $filename &&filetype= "directory" test-r $filename &&perm= "readable" Test-w $filename &&perm= "$perm writable" test-x $filename &&perm= "$perm executable" #4. Start output information echo "the FileName: $filename is a $filetype "echo", the Permisson is: $perm "
Linux Learning Shell script