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

jim jim at well.com
Mon Aug 8 10:32:53 PDT 2016


     They are too! They're also redirection and
pipe, of course.
     What  >  tells the shell is that the stuff
to the left is a complete command and the
stuff to the right is the teet name of a file,
which the shell puts in a system call to tell
the kernel to get the inode number of the file
(create one if the name does not exist) and
then open the file and place the file pointer
to the first byte in the file.
     The other characters work similarly, for
example the  >>  characters work just like
the  >  character except they tell the kernel
to position the file pointer to the position
after the last byte in the file.
     The  |  character tells the shell that the
stuff to the left is one command and the stuff
to the right is another, different command. The
shell tells the kernel to start running the
command at the right and after it's up and ready
then run the command at the left and send its
output to be the input of the command (at the
right) that is sitting there, running, and
ready to catch the data.

     Another command termination character (the
DASH man page has a section on its "control
characters") is the  &  character, which tells
the shell that the stuff to the left is a command
that should run "in the background"; the user can
type another command to the right and the shell
will (tell the kernel to) run the program to the
left in the background and then run the program
to the right in the foreground.

(The DASH man page is glorious, unlike some other
man pages.)



On 08/08/2016 03:00 PM, Michael Paoli wrote:
>> 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/
>>
>
>
>
> _______________________________________________
> 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