You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# an example .env file, which has no export keyword
$ cat .env
FOO=BAR123
# an example script uses $FOO
$ cat echo.sh
echo$FOO# source and export .env file here# yes, -a means enable, +a means disable here
$ set -a;source .env;set +a
# try to access the $FOO var in another script, to show it's exported
$ bash echo.sh
BAR123
Use C-like for loop with var name directly
N=3
# NOTE: you can use N directly here, instead of $N, although $N will also work
for ((i=0; i<N; i++));do
echo "$i/$N: Hello, Shell!"
done
loop on string list
# loop on keywords without spaces
items="apple orange pear"
for item in $items; do
echo $item
done
# if there are spaces, bash array is needed
things=("one word" "two words" "three words")
for item in "${things[@]}"; do
echo "$item"
done
slugify() {
echo "$1" | sed 's/ /-/g' | sed 's/[^a-zA-Z0-9-]//g' | sed 's/--*/-/g' | sed 's/^-\|-$//g'
}
# you could ajust sed patterns to meet your needs
$ slugify '\Fantasy #dragon @statue with wings'
Fantasy-dragon-statue-with-wings