Linux Learning Shell Script

Source: Internet
Author: User
Tags terminates

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:

    1. FileName file exists, does not exist, terminates the program

    2. If it exists, determine whether it is a file or a directory and enter the result

    3. 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

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.