summaryrefslogtreecommitdiffhomepage
path: root/bash.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'bash.html.markdown')
-rw-r--r--bash.html.markdown10
1 files changed, 7 insertions, 3 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index 3f3e49eb..cda877ad 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -25,7 +25,7 @@ Nearly all examples below can be a part of a shell script or executed directly i
[Read more here.](http://www.gnu.org/software/bash/manual/bashref.html)
```bash
-#!/bin/bash
+#!/usr/bin/env bash
# First line of the script is shebang which tells the system how to execute
# the script: http://en.wikipedia.org/wiki/Shebang_(Unix)
# As you already figured, comments start with #. Shebang is also a comment.
@@ -74,8 +74,8 @@ echo ${Variable/Some/A} # => A string
# Substring from a variable
Length=7
-echo ${Variable:0:Length} # => Some st
-# This will return only the first 7 characters of the value
+echo ${Variable:0:$Length} # => Some st
+# This will return 7 characters of the string, starting from the first char
# Default value for variable
echo ${Foo:-"DefaultValueIfFooIsMissingOrEmpty"}
@@ -228,10 +228,13 @@ mv s0urc3.txt dst.txt # sorry, l33t hackers...
# 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 # also goes 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??
+cd - # change to last directory
+# => /home/username/Documents
# Use subshells to work across directories
(echo "First, I'm here: $PWD") && (cd someDir; echo "Then, I'm here: $PWD")
@@ -256,6 +259,7 @@ print("#stderr", file=sys.stderr)
for line in sys.stdin:
print(line, file=sys.stdout)
EOF
+# Variables will be expanded if the first "EOF" is not quoted
# Run the hello.py Python script with various stdin, stdout, and
# stderr redirections: