Penguin

Differences between version 57 and predecessor to the previous major change of BashNotes.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 57 Last edited on Saturday, April 21, 2007 10:18:51 am by BenStaz Revert
Older page: version 52 Last edited on Friday, March 16, 2007 8:16:47 pm by LawrenceDoliveiro Revert
@@ -372,8 +372,11 @@
 !How can I see what my command will look like after bash expands it? 
  
 After typing the command, press ''Esc'' then press ''C-e'' 
  
+!Bash C-style for loop construct  
+  
+for ((i=1; i<100;i++));do echo $i; done;  
  
 !How can I do Division in bash using floating point numbers? 
  
 Use ''bc'' 
@@ -395,12 +398,51 @@
 if [ $bla -eq 1 -o $cars -eq 3 -o $monkeys -eq 4 ]; then 
  echo "Westside" 
 fi 
 </verbatim> 
+  
+!How can I supply filenames with a prefix of '-' '--' as arguments to a program?  
+  
+Say you have a file called '--test'.  
+If you wanted to use vim to edit this file then you would do:  
+  
+*vim -- --test  
+  
+The '--' tells the command that what follows is an argument, NOT to interpret them as options.  
+  
+!How to directly interpret a shell script by the current shell. (Without forking a subshell)  
+  
+*. <myscript>  
+  
+If the above script makes a change to the environment, it is the environment of this shell that is changed.  
+So if inside the script we change the directory, then when the script has finished being interpreted we will find ourselves in the new directory.  
+  
+Note : This can be handy when you want to reset the shell environment variables.  
+  
+Just do:  
+  
+*. ~~/.bashrc  
+  
+!Set vi mode in bash  
+  
+Vi mode allows for the use of vi like commands when at the bash prompt. When set to this mode initially you will be in insert mode (be able to type at the prompt unlike when you enter vi). Hitting the escape key takes you into command mode. To enable this do:  
+  
+*set -o vi  
+  
+One thing I do like about vi mode, is how easy it is to edit really long commands. (Of course some will argue that I should just use a bash script instead)  
+  
+When in ''vi mode'' press 'esc' to enter ''command mode''. Now press 'v'.  
+This will start up the default editor (as defined by the EDITOR environment variable) and your command will be displayed.  
+Edit it to your liking (feel free to use multiple lines for loops/if statements etc), save and exit.  
+Your command will be executed.  
+  
+To escape out of ''vi mode'' simply type:  
+  
+*set +o vi  
  
 !! See also 
  
 * CommonErrors, under "Your shell hangs" 
 * BashOneLiners 
 * SpacesInPathNames 
 * PortabilityNotes 
 * [bash reference manual|http://www.gnu.org/software/bash/manual/bashref.html]