Add echo
This commit is contained in:
		
							parent
							
								
									dbce61c760
								
							
						
					
					
						commit
						73e7ba9c1c
					
				@ -13,3 +13,4 @@ Implemeted utilities:
 | 
				
			|||||||
 * `yes`
 | 
					 * `yes`
 | 
				
			||||||
 * `dirname`
 | 
					 * `dirname`
 | 
				
			||||||
 * `basename`
 | 
					 * `basename`
 | 
				
			||||||
 | 
					 * `echo`
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										24
									
								
								echo/echo.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								echo/echo.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"flag"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
						s "strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var noNewline = flag.Bool("n", false, "Do not print the terminating newline.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func echo(strings []string, noNewline bool) {
 | 
				
			||||||
 | 
						str := s.Join(strings, " ")
 | 
				
			||||||
 | 
						if noNewline {
 | 
				
			||||||
 | 
							fmt.Print(str)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							fmt.Println(str)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						flag.Parse()
 | 
				
			||||||
 | 
						echo(os.Args[1:], *noNewline)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user