How to obtain the number of command lines or the number of system environment changes

Source: Internet
Author: User

First, obtain the command line metric data:

Usage: [email protected]: ~ /Code/go/self $./SUM 1 2 4

package mainimport "fmt"import "os"import "strconv"func main() int{arg_num := len(os.Args)fmt.Printf("the num of input is %d\n",arg_num)fmt.Printf("they are :\n")for i := 0 ; i < arg_num ;i++{fmt.Println(os.Args[i])}sum := 0for i := 1 ; i < arg_num; i++{curr,err := strconv.Atoi(os.Args[i])if(err != nil){fmt.Println("error happened ,exit")return 1}sum += curr}fmt.Printf("sum of Args is %d\n",sum)return 0}

Environment Changes of the fetch system:

package mainimport "fmt"import "os"func main(){environ := os.Environ()for i := range environ {fmt.Println(environ[i])}fmt.Println("------------------------------------------------------------\n")logname := os.Getenv("LOGNAME")fmt.Printf("logname is %s\n",logname)}


How to obtain the number of command lines or the number of system environment changes

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.