Open 7dir opened 5 years ago
get_name() {
echo "John"
}
echo "You are $(get_name)"
{A,B} | Same as A B
-- | --
{A,B}.js | Same as A.js B.js
{1..5} | Same as 1 2 3 4 5
echo "I'm in $(pwd)"
echo "I'm in `pwd`"
NAME="John"
echo "Hi $NAME" #=> Hi John
echo 'Hi $NAME' #=> Hi $NAME
if [[ -z "$string" ]]; then
echo "String is empty"
elif [[ -n "$string" ]]; then
echo "String is not empty"
fi
Basics
name="John"
echo ${name}
echo ${name/J/j} #=> "john" (substitution)
echo ${name:0:2} #=> "Jo" (slicing)
echo ${name::2} #=> "Jo" (slicing)
echo ${name::-1} #=> "Joh" (slicing)
echo ${name:(-1)} #=> "n" (slicing from right)
echo ${name:(-2):1} #=> "h" (slicing from right)
echo ${food:-Cake} #=> $food or "Cake"
How do I check whether a variable has an even (not odd) numeric value in bash?
foo=6
if [ $((foo%2)) -eq 0 ];
then
echo "even";
else
echo "odd";
fi
a=4
[ $((a%2)) -eq 0 ] && echo "even"