summaryrefslogtreecommitdiffhomepage
path: root/bash.html.markdown
diff options
context:
space:
mode:
authorDavid Hsieh <davidhsiehlo@gmail.com>2016-03-11 08:39:55 -0600
committerDavid Hsieh <davidhsiehlo@gmail.com>2016-03-11 08:39:55 -0600
commitceb99e14019672309ca80350054b7bb1a6642a48 (patch)
tree1cca5af13a146c0a36ef760b6264d18875290ec0 /bash.html.markdown
parent51c2f7ce28caf1cc654bcafc4063f3012cc2f0c3 (diff)
parent8d1e2e31ef9c62e2833ccb83cde78caef668f044 (diff)
Merge branch 'adambard-master' into r-spanish
Diffstat (limited to 'bash.html.markdown')
-rw-r--r--bash.html.markdown17
1 files changed, 13 insertions, 4 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 211d2944..f3c9cccc 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -83,7 +83,7 @@ echo Hello, $Name!
# We have the usual if structure:
# use 'man test' for more info about conditionals
-if [ $Name -ne $USER ]
+if [ $Name != $USER ]
then
echo "Your name isn't your username"
else
@@ -91,12 +91,12 @@ else
fi
# NOTE: if $Name is empty, bash sees the above condition as:
-if [ -ne $USER ]
+if [ != $USER ]
# which is invalid syntax
# so the "safe" way to use potentially empty variables in bash is:
-if [ "$Name" -ne $USER ] ...
+if [ "$Name" != $USER ] ...
# which, when $Name is empty, is seen by bash as:
-if [ "" -ne $USER ] ...
+if [ "" != $USER ] ...
# which works as expected
# There is also conditional execution
@@ -130,6 +130,15 @@ ls -l # Lists every file and directory on a separate line
# .txt files in the current directory:
ls -l | grep "\.txt"
+# Since bash works in the context of a current directory, you might want to
+# run your command in some other directory. We have cd for changing location:
+cd ~ # change to home directory
+cd .. # go up one directory
+ # (^^say, from /home/username/Downloads to /home/username)
+cd /home/username/Documents # change to specified directory
+cd ~/Documents/.. # still in home directory..isn't it??
+
+
# 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":