# => I'm in /path/of/current
echo "I'm in $(PWD)"
# Same as:
echo "I'm in `pwd`"
See: Command substitution
# => I'm in /path/of/current
echo "I'm in $(PWD)"
# Same as:
echo "I'm in `pwd`"
See: Command substitution
echo {A,B}.js
Expression | Description |
---|---|
{A,B} |
Same as A B |
{A,B}.js |
Same as A.js B.js |
{1..5} |
Same as 1 2 3 4 5 |
See: Brace expansion |
if [[ -z "$string" ]]; then
echo "String is empty"
elif [[ -n "$string" ]]; then
echo "String is not empty"
fi
See: Conditionals
Expression | Description |
---|---|
$1 ⦠$9 |
Parameter 1 … 9 |
$0 |
Name of the script itself |
$1 |
First argument |
${10} |
Positional parameter 10 |
$# |
Number of arguments |
$$ |
Process id of the shell |
$* |
All arguments |
$@ |
All arguments, starting from first |
$- |
Current options |
$_ |
Last argument of the previous command |
See: Special parameters |
# This is an inline Bash comment.
: '
This is a
very neat comment
in bash
'
Multi-line comments use :'
to open and '
to close
NAME="John"
echo ${NAME} # => John (Variables)
echo $NAME # => John (Variables)
echo "$NAME" # => John (Variables)
echo '$NAME' # => $NAME (Exact string)
echo "${NAME}!" # => John! (Variables)
NAME = "John" # => Error (about space)
#!/bin/bash
VAR="world"
echo "Hello $VAR!" # => Hello world!
Execute the script
$ bash hello.sh