summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bash.html.markdown45
-rw-r--r--r.html.markdown11
-rw-r--r--tmux.html.markdown3
3 files changed, 46 insertions, 13 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 81d586c4..3b163638 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -111,12 +111,45 @@ ls -l # Lists every file and directory on a separate line
# .txt files in the current directory:
ls -l | grep "\.txt"
-# You can also redirect a command, input and error output.
-python2 hello.py < "input.in"
-python2 hello.py > "output.out"
-python2 hello.py 2> "error.err"
-# The output error will overwrite the file if it exists, if you want to
-# concatenate them, use ">>" instead.
+# You can redirect command input and output (stdin, stdout, and stderr).
+# Read from stdin until ^EOF$ and overwrite hello.py with the lines
+# between "EOF":
+cat > hello.py << EOF
+#!/usr/bin/env python
+from __future__ import print_function
+import sys
+print("#stdout", file=sys.stdout)
+print("#stderr", file=sys.stderr)
+for line in sys.stdin:
+ print(line, file=sys.stdout)
+EOF
+
+# Run hello.py with various stdin, stdout, and stderr redirections:
+python hello.py < "input.in"
+python hello.py > "output.out"
+python hello.py 2> "error.err"
+python hello.py > "output-and-error.log" 2>&1
+python hello.py > /dev/null 2>&1
+# The output error will overwrite the file if it exists,
+# if you want to append instead, use ">>":
+python hello.py >> "output.out" 2>> "error.err"
+
+# Overwrite output.txt, append to error.err, and count lines:
+info bash 'Basic Shell Features' 'Redirections' > output.out 2>> error.err
+wc -l output.out error.err
+
+# Run a command and print its file descriptor (e.g. /dev/fd/123)
+# see: man fd
+echo <(echo "#helloworld")
+
+# Overwrite output.txt with "#helloworld":
+cat > output.out <(echo "#helloworld")
+echo "#helloworld" > output.out
+echo "#helloworld" | cat > output.out
+echo "#helloworld" | tee output.out >/dev/null
+
+# Cleanup temporary files verbosely (add '-i' for interactive)
+rm -v output.out error.err output-and-error.log
# Commands can be substituted within other commands using $( ):
# The following command displays the number of files and directories in the
diff --git a/r.html.markdown b/r.html.markdown
index 7cb56fd7..c555d748 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -179,7 +179,7 @@ c(3,3,3,2,2,1) # 3 3 3 2 2 1
# You can also have infinitely large or small numbers
class(Inf) # "numeric"
class(-Inf) # "numeric"
-# You might use "Inf", for example, in integrate( dnorm(x), 3, Inf);
+# You might use "Inf", for example, in integrate(dnorm, 3, Inf);
# this obviates Z-score tables.
# BASIC ARITHMETIC
@@ -236,11 +236,12 @@ c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE
# FACTORS
# The factor class is for categorical data
# Factors can be ordered (like childrens' grade levels) or unordered (like gender)
-factor(c("female", "female", "male", "NA", "female"))
-# female female male NA female
-# Levels: female male NA
+factor(c("female", "female", "male", NA, "female"))
+# female female male <NA> female
+# Levels: female male
# The "levels" are the values the categorical data can take
-levels(factor(c("male", "male", "female", "NA", "female"))) # "female" "male" "NA"
+# Note that missing data does not enter the levels
+levels(factor(c("male", "male", "female", NA, "female"))) # "female" "male"
# If a factor vector has length 1, its levels will have length 1, too
length(factor("male")) # 1
length(levels(factor("male"))) # 1
diff --git a/tmux.html.markdown b/tmux.html.markdown
index de3a8341..9eb96303 100644
--- a/tmux.html.markdown
+++ b/tmux.html.markdown
@@ -2,8 +2,7 @@
category: tool
tool: tmux
contributors:
- - ["kaernyk", "https://github.com/kaernyk"]
- - ["jmaud", "https://github.com/jmaud"]
+ - ["wzsk", "https://github.com/wzsk"]
filename: LearnTmux.txt
---