[sf-lug] > and >> and < and << and |

Michael Paoli Michael.Paoli at cal.berkeley.edu
Mon Aug 8 08:00:20 PDT 2016


> different command. (The shell has other
> command-line termination characters, such
> as > and >> and < and << and | and more.)

Actually, > and >> and < and << and | aren't shell termination
characters, but rather various forms of redirection.
The last of those (|) forming a pipeline - which is a form
of more complex command/list, whereas the others are used for generally
simpler redirection.  Shell termination characters are semi-colon (;)
and newline (typically stty settings will map carriage return of
keyboard input to newline).

Example:
$ >out echo output
$ cat out
output
$
We can see quite clearly in the above, the > did not terminate our shell
command at all, but rather was used to redirect standard output of our
echo command to a file we named out.

Can also add newlines while typing the echo command on a single line,
e.g.:
$ cat out && echo -e '\n\n'
output



$
I'll leave explaining the details of the above as an exercise.  :-)

> From: jim <jim at well.com>
> Subject: [sf-lug] dumb little command-line trick
> Date: Mon, 8 Aug 2016 05:15:08 +0000

>
> (optional reading)
>     (I used to teach intro programming classes
> and miss it.) This is for people getting
> started using the command-line.
> ------------------------------------------------
>     Some command-line users I admire issue
> a command, watch its output, and then hit
> the  Enter  key a few times to create some
> blank lines that make some space between
> the output of the command and the command
> that they next invoke:
>
> $ doit
> this and that and more
> $
> $
> $
> $ icommandyou be good
> gurgle burble
>
>     I invoke the  doit  command, which prints
> its output (this and that and more) then I hit
> the  Enter  key three times and then invoke
> the  icommandyou be good  command, which
> prints its output (gurgle burble). I review
> what I've done and have convenient blank lines
> separating the two different commands and their
> outputs.
>
>
>     My dumb little trick is similar, but I use
> the  echo  command and the  ;  (semi-colon)
> command-separation character and then the command
> I want to run.
>
> $ echo "
>
>
> " ; doit
>
>
>
> this and that and more
> $
>
>     For those interested, my trick has three parts,
>
> echo "
>
>
> "
> ## what this does it to print three blank lines
> to the display.
>
> as well as
>
> ;
> ## what this does is to tell the shell that
> everything to the left is a command and
> everything to the right is a completely
> different command. (The shell has other
> command-line termination characters, such
> as > and >> and < and << and | and more.)
>
> doit
> ## this is the command I want to run.
>
>     My dumb little command-line trick lets me
> run a command but issue a few blank lines
> before the command runs, so I get a little
> blank space above the output of the command.
>
>     I can make a shell script that saves a
> little time and possible typing errors.
>
> $ pwd
> /home/jim/bin  ## here's my current directory
> $ echo $PATH
> /home/jim/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
> ## I set my PATH environment variable to include my
> own  bin  directory, /home/jim/bin
>
> $ vi blns
> echo "
>
>
> "
> $ chmod 755 blns
>
>     Now I can use my dumb little trick like this
>
> $ blns ; doit
>
> ## I suppose I could have put the  ;  command
> ## separation character in the shell script,
> ## but for some reason I feel better making
> ## myself type that character
>
> ## I made up the name  blns  to suggest "blank lines".
>
>
>
> _______________________________________________
> sf-lug mailing list
> sf-lug at linuxmafia.com
> http://linuxmafia.com/mailman/listinfo/sf-lug
> Information about SF-LUG is at http://www.sf-lug.org/
>






More information about the sf-lug mailing list