Skip to content

Commit

Permalink
Merge pull request #605 from denis-sokolov/simple-sh-syntax
Browse files Browse the repository at this point in the history
for/if/while: add
  • Loading branch information
igorshubovych committed Jan 7, 2016
2 parents 545b107 + 27cc018 commit c066ac0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pages/common/for.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# for

> Shell loop over parameters
- Perform a command with different arguments.

`for argument in 1 2 3; do {{command $argument}}; done`

- Perform a command in every directory.

`for d in *; do (cd $d; {{command}}); done`
11 changes: 11 additions & 0 deletions pages/common/if.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# if

> Simple shell conditional
- Echo a different thing depending on a command's success.

`{{command}} && echo "success" || echo "failure"`

- Full if syntax.

`if {{condition}}; then echo "true"; else echo "false"; fi`
11 changes: 11 additions & 0 deletions pages/common/while.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# while

> Simple shell loop
- Read stdin and perform an action on every line.

`while read line; do echo "$line"; done`

- Execute a command forever once every second.

`while :; do {{command}}; sleep 1; done`

0 comments on commit c066ac0

Please sign in to comment.