github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/exp/rush/cd.go (about) 1 // Copyright 2012 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 // our first builtin: cd 6 package main 7 8 import ( 9 "errors" 10 "os" 11 ) 12 13 var errCdUsage = errors.New("usage: cd one-path") 14 15 func init() { 16 addBuiltIn("cd", cd) 17 } 18 19 func cd(c *Command) error { 20 if len(c.argv) != 1 { 21 return errCdUsage 22 } 23 24 err := os.Chdir(c.argv[0]) 25 return err 26 }