Skip to content

Instantly share code, notes, and snippets.

@Anna-Myzukina
Last active September 15, 2018 20:22
Show Gist options
  • Save Anna-Myzukina/c6fb46be05da237c4f69a963edfe577b to your computer and use it in GitHub Desktop.
Save Anna-Myzukina/c6fb46be05da237c4f69a963edfe577b to your computer and use it in GitHub Desktop.
learnyoubash
#!/usr/bin/env bash
echo "Hello, world!"
#1.touch hello.bash
#2.chmod +x hello.bash
#3. ./hello.bash
#!/usr/bin/env bash
greater_even() {
# return if it's out of range
[[ $1 -lt $2 ]] || return
indent="$3"
if [[ $(( $1 % 2 )) -eq 0 ]]; then
i=0
for (( i = 0; i < $indent; i++ )); do
echo -n ' '
done
echo $1
# update indent only if number is even
indent=$(( indent + 1 ))
fi
greater_even $(( $1 + 1 )) $2 $indent
}
main() {
echo $FUNCNAME
greater_even $1 $2 1
}
main $1 $2
#!/usr/bin/env bash
set -vn
echo $@
touch $@
mkdir ./folder
mv file* ./folder
cd ./folder
ls
set +vn
#!/usr/bin/env bash
echo "User $USER in directory $PWD."
#!/usr/bin/env bash
echo "1: $1"
echo "3: $3"
echo "5: $5"
#!/usr/bin/env bash
output=(I am "${@:2:2}" and "${@:4:1}")
echo "${output[*]}"
#!/usr/bin/env bash
RESULT=$(( ($3 + $2) * $1))
echo project-$RESULT/{src,dest,test}/{index,util}.js
#!/usr/bin/env bash
$1 || echo "First parameter is false."
$2 && pwd
$3 && ls || echo "Third parameter is false."
#!/usr/bin/env bash
if [[ $1 -ge 0 && $1 -lt 12 ]]; then
echo "Good morning!"
elif [[ $1 -ge 12 && $1 -lt 18 ]]; then
echo "Good afternoon!"
elif [[ $1 -ge 18 && $1 -lt 24 ]]; then
echo "Good evening!"
else
echo "Error!"
fi
#!/usr/bin/env bash
case "$1" in
("jpg"|"jpeg")
echo 'It is jpeg.'
;;
"png")
echo 'It is png.'
;;
"gif")
echo 'It is gif.'
;;
*)
echo "$1 is not an image!"
esac
#!/usr/bin/env bash
i=$1
while [[ $i -lt $2 ]]; do
[ ! $(( $i % 2 )) -eq 0 ] || echo $i
i=$(( $i + 1 ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment