Remember the Pipe
Sometimes, you want to save output. For that, the shell gives you redirection.
Sometimes, though, you want to save the pipeline that you grew to get the
output.
You could recall it, write it down, and then type it into a file, but there's
an easier way.
After you run the pipeline, make your next command "fc."
Try this:
Once
And as long as you're in there, you could even take your time, add shebang lines and comments, and change the layout. The shell gives you command-line history and pipes, for quick-and-dirty script development, and then gives you
The default editor is vi, but you can make it whatever you want.
Being able to write to a file and create a shell script, once you've edited it, is just a side-effect of the shell's clean design.
And now that we're talking about command history, we'll make that next week's introductory topic.
Sometimes, though, you want to save the pipeline that you grew to get the
output.
You could recall it, write it down, and then type it into a file, but there's
an easier way.
After you run the pipeline, make your next command "fc."
Try this:
(You've run other things since the pipeline? Recall it with command history, rerun it, then typels | wc -l
fc
fc
)Once
fc
puts the pipeline into a text editor, you can write it out to a file. Presto! A shell script.And as long as you're in there, you could even take your time, add shebang lines and comments, and change the layout. The shell gives you command-line history and pipes, for quick-and-dirty script development, and then gives you
fc
, to capture what works and clean it up.The default editor is vi, but you can make it whatever you want.
Notice that when you exit the editor, the command is rerun.EDITOR=kate
ls | wc -l
fc
fc
stands for "fix command". Instead of editing a long command line with arrow keys, you can edit it with your favorite text editor.Being able to write to a file and create a shell script, once you've edited it, is just a side-effect of the shell's clean design.
And now that we're talking about command history, we'll make that next week's introductory topic.
0 Comments:
Post a Comment
<< Home