vimwiki/tech/Bash.wiki

118 lines
1.4 KiB
Plaintext

= Bash =
The shell itself
== Common syntax ==
I tend to forget it sometimes lol
=== Brackets ===
Remember '\[' is a program unto itself. Here are some common flags
* -z
- empty string
* -n not
- empty string
* == aka -eq
- equal
* != aka -ne
- not equal
* -lt
- less than
* -gt
- greater than
* -ge
- greater than or equal
* !
- not
* &&
- and
* ||
- or
* -e
- file exists
* -r
- is readable
* -h
- is symlink
* -d
- is directory
* -s
- has data in it
* -f
- is file
* -x
- is executable
=== Variables ===
{{{
var=55
echo $var
}}}
=== While ===
{{{
while [ condition ]; do
echo "Hello world"
done
}}}
=== Arays ===
{{{
Fruits={'Apple','Banana','Orange'}
Fruits[0]="Apple"
echo ${Fruits[0]}
declare -A sounds
sounds[dog]="bark"
sounds[cow]="moo"
sounds[bird]="tweet"
sounds[wolf]="howl"
echo ${sounds[dog]} # Dog's sound
echo ${sounds[@]} # All values
echo ${!sounds[@]} # All keys
echo ${#sounds[@]} # Number of elements
unset sounds[dog] # Delete dog
}}}
=== Math ===
{{{
$((a + 200)) #add 200 to a
}}}
=== Strings ===
{{{
${FOO%suffix} #remove suffix from foo
${FOO#prefix} #remove prefix from foo
${FOO/from/to} #replace first instance of from with to
${FOO//from/to} #replace all instances of from with to
${#FOO} #length of foo
}}}
== Common tasks ==
Rename push all .png files through convert
{{{
for file in *.png; do
convert $file "${file%.png}.eps"
done
}}}
[[index]]