github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/ash/exit.go (about) 1 // Copyright 2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "errors" 9 "os" 10 "strconv" 11 ) 12 13 func init() { 14 addBuiltIn("exit", exitBuiltin) 15 } 16 17 func exitBuiltin(c *Command) error { 18 var err error 19 if len(c.argv) == 0 { 20 os.Exit(0) 21 } else if len(c.argv) > 1 { 22 err = errors.New("Too many arguments") 23 } else if ret, err2 := strconv.Atoi(c.argv[0]); err2 == nil { 24 os.Exit(ret) 25 } else { 26 err = errors.New("Non numeric argument") 27 } 28 return err 29 }