Editing BASH and Octave

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
 
One of the nice features of Octave (and similar languages) is that you don't have to compile the code that you generate. It is interpreted by Octave instead. This make learning the language easy by trial-and-error. Very often it is useful to save what you have learned from you fiddlings during the current Octave 'session' that you have opened for this fiddling.
 
One of the nice features of Octave (and similar languages) is that you don't have to compile the code that you generate. It is interpreted by Octave instead. This make learning the language easy by trial-and-error. Very often it is useful to save what you have learned from you fiddlings during the current Octave 'session' that you have opened for this fiddling.
Octave keeps a copy of all your command you give on the Octave command line. In Linux it is saved in the file {{Path|~/.octave_hist}}.
+
Octave keeps a copy of all your command you give on the Octave command line. In Linux it is saved in the file {{Codeline|~/.octave_hist}}.
  
If you want to save all the Octave commands you gave during the last Octave session, generate a file {{Path|octave_save_last_session}} in your directory {{Path|~/bin}} and put the following inside:
+
If you want to save all the Octave commands you gave during the last Octave session, generate a file {{Codeline|octave_save_last_session}} in your directory {{Codeline|~/bin}} and put the following inside:
 
(that is: you have to open a terminal on your Linux computer and type the following commands on the terminal command line (make sure it is the BASH shell).
 
(that is: you have to open a terminal on your Linux computer and type the following commands on the terminal command line (make sure it is the BASH shell).
  
<syntaxhighlight lang="bash" style="font-size:13px">
+
{{Code||<syntaxhighlight lang="bash" style="font-size:13px">
 
#!/bin/bash                                                                                                                                                                                 
 
#!/bin/bash                                                                                                                                                                                 
 
filename='octave_save_last_session.m'
 
filename='octave_save_last_session.m'
Line 13: Line 13:
  
 
tac $HOME/.octave_hist | awk '/^#/ {found++} ; found<2 ' |tac >$filename
 
tac $HOME/.octave_hist | awk '/^#/ {found++} ; found<2 ' |tac >$filename
</syntaxhighlight>
+
</syntaxhighlight>}}
  
Then you still need to tell the BASH shell to make this file {{Path|~/bin/octave_save_last_session}} executable:
+
Then you still need to tell the BASH shell to make this file {{Codeline|~/bin/octave_save_last_session}} executable:
  
  chmod u+x ~/bin/octave_save_last_session
+
{{Code||<syntaxhighlight lang="bash" style="font-size:13px">
 +
chmod u+x ~/bin/octave_save_last_session
 +
</syntaxhighlight>}}
  
Now, imaging you have 'played around' in an interactive Octave session to try/test something: you want to save the commands you just used to not-forget. Just close the Octave session. If (in Linux) you close Octave that you have started from the command line, you will automatically return to the command line. Now you want to have a seperate copy of your last session put in a file (a {{Codeline|*.m}} file). On the command line, you just type {{Codeline|octave_save_last_session}}, and the last session (only!) is copied from the {{Path|~/.octave_hist}} file and saved to {{Path|octave_save_last_session.m}}. You can edit that file to remove parts you don't want to save, or you can re-execute the commands by <code>octave --persist octave_save_last_session.m</code>.
+
Now, imaging you have 'played around' in an interactive Octave session to try/test something: you want to save the commands you just used to not-forget. Just close the Octave session. If (in Linux) you close Octave that you have started from the command line, you will automatically return to the command line. Now you want to have a seperate copy of your last session put in a file (a {{Codeline|*.m}} file). On the command line, you just type {{Codeline|octave_save_last_session}}, and the last session (only!) is copied from the {{Codeline|~/.octave_hist}} file and saved to {{Codeline|octave_save_last_session.m}}. You can edit that file to remove parts you don't want to save, or you can re-execute the commands by {{Codeline|octave --persist octave_save_last_session.m}}.
  
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks]]

Please note that all contributions to Octave may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Octave:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Templates used on this page: