alan@drivax.UUCP (Alan Fargusson) (06/04/85)
This is an echo like command that has some of the features that the older echo commands had (like -n) as well as some new features. While I was writing this I found some things in the System V echo command that looked like bugs. For instance if you type 'echo \\0077' you get a '?'. The way that the manual entry reads I expected a bell followed by a '7'. In show you get a bell followed by a '7'. Show is based on a version of echo that was posted to net.sources which had a -q flag to prevent the echoing of the arguments. This feature is retained. I found that the System V echo will not echo its arguments if you type 'echo \\c args', and show has this feature also. -- cut here -- -- cut here -- -- cut here -- -- cut here -- -- cut here -- # This is a shell archive. Remove anything before this line, then # unpack it by saving it in a file and typing "sh file". (Files # unpacked will be owned by you and have default permissions.) # # This archive contains: # show.1 show.c echo x - show.1 cat > "show.1" << '//E*O*F show.1//' .TH SHOW 1 "30 May 1985" .SH NAME show \- show arguments .SH SYNOPSIS .B show [ .B \-nqr ] [ arg ] ... .SH DESCRIPTION .I Show writes its arguments separated by blanks and terminated by a newline on the standard output. If the flag .B \-n is used then the output is not terminated by a newline. If the flag .B \-q is used, then .I show runs quietly (arguments are not showed). .B \-r is used to show arguments randomly. .B \-\- causes the rest of the arguments to be showed, allows arguments beginning with a .B \- to be showed. .PP .I Show understands C-like escape conventions. These are \\b for backspace, \\a for bell, \\f for form feed, \\n for new line, \\r for a return, \\t for tab, \\v for vertical tab, \\x followed by one or two hex digits, \\ followed by string of from one to three octal digits. \\c causes .I show to exit. Beware of conflicts with the shell's use of \\. .PP .I Show is useful for producing diagnostics in shell programs and for writing constant data on pipes. Note that .I show will write a new line even if no arguments are given. This differs from the .I echo command. .I Show with the .B \-q or .B \-r option is not useful. .SH BUGS probably! //E*O*F show.1// echo x - show.c cat > "show.c" << '//E*O*F show.c//' #include <stdio.h> main(argc, argv) int argc; char **argv; { register int i, nflg, rflg; nflg = rflg = 0; while ( argc > 1 && argv[ 1 ][ 0 ] == '-' ) { i = 0; while ( argv[ 1 ][ ++i ] ) { switch ( argv[ 1 ][ i ] ) { case '-': argc--; argv++; goto skip; case 'q': exit( 0 ); case 'n': nflg++; break; case 'r': rflg++; srand( getpid() ); break; default: fputs( "usage: show [-qnr] string\n", stderr ); exit( 2 ); } } argc--; argv++; } skip: for ( i = 1; i < argc; i++ ) { if ( ( ( ! rflg ) || ( rflg && ( rand() & 010 ) ) ) ) { output( argv[i] ); if ( i < argc-1 ) putchar( ' ' ); } } if ( ! nflg ) putchar( '\n' ); exit( 0 ); } output( string ) char *string; { int val; char c; while ( *string ){ if ( *string == '\\' ) { string++; switch ( *string++ ) { case '\0': break; case 'a': putchar( '\007' ); break; case 'b': putchar( '\010' ); break; case 'c': exit( 0 ); case 'f': putchar( '\014' ); break; case 'n': putchar( '\n' ); break; case 'r': putchar( '\r' ); break; case 't': putchar( '\t' ); break; case 'v': putchar( '\013' ); break; case 'x': if ( *string == '\0' ) break; val = hexconvert( *string++ ); if ( ( *string >= '0' && *string <= '9' ) || ( *string >= 'a' && *string <= 'f') || ( *string >= 'A' && *string <= 'F') ) { val = (val<<4)+hexconvert( *string++ ); } putchar( (char)val ); break; default: string--; if ( *string >= '0' && *string <= '7' ) { val = (int)( *string++ - '0' ); if ( *string >= '0' && *string <= '7' ) { val = (val<<3)+(int)( *string++ - '0' ); if ( *string >= '0' && *string <= '7' ) { val = (val<<3)+(int)( *string++ - '0' ); } } putchar( (char)val ); } else putchar( *string++ ); } } else { putchar( *string++ ); } } } hexconvert( c ) char c; { if ( c >= '0' && c <= '9' ) return (int)( c - '0' ); else if ( c >= 'a' && c <= 'f' ) return (int)( c - 'a' + 10 ); else if ( c >= 'A' && c <= 'F' ) return (int)( c - 'A' + 10 ); else return 0; } //E*O*F show.c// exit 0 -- Alan Fargusson. { ihnp4, amdahl, mot }!drivax!alan