1 2 /* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 * 6 * A portable "echo" program that supports "-n" option: 7 * echo Hello world! 8 * echo "Hello world!" 9 * echo -n Hello world! 10 * echo 11 * 12 * It also passes "\c" characters as is. 13 */ 14 15 16 #include <stdio.h> 17 #include <string.h> 18 19 20 int main(int argc,char * const * argv)21main(int argc, char *const *argv) 22 { 23 int i = 1; 24 int nl = 1; 25 26 if (argc > 1) { 27 if (strcmp(argv[1], "-n") == 0) { 28 nl = 0; 29 i++; 30 } 31 32 while (i < argc) { 33 printf("%s%s", argv[i], (i == argc - 1) ? "" : " "); 34 i++; 35 } 36 } 37 38 if (nl) { 39 printf("\n"); 40 } 41 42 return 0; 43 } 44