From charlesreid1

No edit summary
Line 29: Line 29:
Looping in bash is really simple, and convenient - you can use other unix commands (most obviously "ls") to create lists, and then loop over each element of those lists.  For example, if I want to print out the name of every file in my home directory (granted, not very useful, but this is just an example), I can do this:
Looping in bash is really simple, and convenient - you can use other unix commands (most obviously "ls") to create lists, and then loop over each element of those lists.  For example, if I want to print out the name of every file in my home directory (granted, not very useful, but this is just an example), I can do this:


<syntaxhighlight lang="bash">
<source lang="bash">


for i in `/bin/ls -1 $HOME`; do
for i in `/bin/ls -1 $HOME`; do
Line 35: Line 35:
done
done


</syntaxhighlight>
</source>
 
To do some serious bash looping kung-fu, check out [[Xargs]].


== Math ==
== Math ==

Revision as of 08:42, 12 April 2011

Bash Guide

Using Bash

Setting the default shell: http://www.unix.com/shell-programming-scripting/32664-how-change-default-shell-linux.html


Startup Process

source /etc/profile

source ~/.profile

(source ~/.bash_profile?)

source /etc/bashrc

source ~/.bashrc


Dot Files

Bash Scripting

Looping

Looping in bash is really simple, and convenient - you can use other unix commands (most obviously "ls") to create lists, and then loop over each element of those lists. For example, if I want to print out the name of every file in my home directory (granted, not very useful, but this is just an example), I can do this:

for i in `/bin/ls -1 $HOME`; do
    echo $i
done

To do some serious bash looping kung-fu, check out Xargs.

Math

Bash Commands

Editing Commands

The following are keyboard shortcuts for easy navigation/editing of commands that are on the Bash command line.

Movement

  • C-a - Move to beginning of line
  • C-e - Move to end of line


  • M-f - Move forward 1 word
  • M-b - Move backward 1 word


  • C-f - Move forward 1 character
  • C-b - Move backward 1 character

Cutting and Pasting

  • C-k - kill (cut) from cursor to end of line
  • C-w - kill (cut) from cursor to previous whitespace
  • C-y - yank (paste) previously killed text at cursor

Uncategorized

  • C-L - clear screen, reprint current line at top
  • C-u - undo last edit
  • C-d - delete character under cursor

References

Floating point math in the shell:

http://www.novell.com/coolsolutions/tools/17043.html

Fast bash math:

http://www.bytemycode.com/snippets/snippet/350/

Bash script iterate through array of values

http://www.tech-recipes.com/rx/636/bash-shell-script-iterate-through-array-values/