Skip to content

Shellscript

cotrTypesBoolFalse

Bash Boolean False

Terminal window
# Bash represents false as 0.

cotrVarString

Bash Create String Variable

Terminal window
# Assign a string value:
${1:myString}=${2:'myValue'}

cotrVar

Bash Variable

Terminal window
${1:myVar}=${2:value}

cotrIf

Bash If Statement

Terminal window
if [ ${1:condition} ]; then
${2:// Your code here}
fi

cotrTypeCompare

Bash Type Comparison

Terminal window
# Bash doesn't have direct type comparison, but you can use file or grep for basic checks.

cotrStructure

Bash Project Structure (High-Level)

Terminal window
# Recommended High-Level Bash Project Structure:
# - bin/
# - Contains executable scripts.
# - lib/
# - Contains reusable functions and libraries.
# - src/
# - Contains source code for scripts.
# - test/
# - Contains unit tests.
# Note:
# - This is a basic structure; adjust based on project complexity and preferences.

cotrStructureFeatures

Bash Project Structure (Feature/Module)

Terminal window
# Organize source code by feature or module within src/:
# - src/
# - rendering/
# - Contains scripts for rendering features.
# - physics/
# - Contains scripts for physics features.
# - networking/
# - Contains scripts for networking features.
# - ... (Organize by feature or module)
# Note:
# - This approach promotes modularity and is suitable for larger projects.

cotrTypeConvert

Bash Type Conversion

Terminal window
# Bash is dynamically typed, so explicit conversion is often not needed.
# However, you can use tools like awk or bc for specific conversions.

cotrTypes

Bash Types

Terminal window
# Bash is dynamically typed, but common data types include:
- string: Textual data
- integer: Numeric data (whole numbers)
- float: Numeric data (decimals)
- array: Ordered collection of values
- associative array: Key-value pairs

cotrVarStatic

Bash Static Variable

Terminal window
# Bash doesn't have static variables in the same way as some other languages.

cotrInfo

Bash Info

Terminal window
Typing: Dynamically typed
Paradigm: Imperative
Compilation: Interpreted
Concurrency: No

cotrConst

Bash Constant

Terminal window
# Bash uses readonly variables for constants:
readonly ${1:myConst}=${2:value}

cotrFuncArrow

Bash Arrow Function

Terminal window
# Bash doesn't have arrow functions.

cotrTypesBool

Bash Boolean Type

Terminal window
# Bash uses 0 for false and non-zero values for true.

cotrCommentMulti

Bash Multi-Line Comment

Terminal window
: <<'END'
${1:Your comment here}
${2:Your comment here}
${3:Your comment here}
END

cotrFunc

Bash Function

Terminal window
${2:myFunction}() {
${3:// Your code here}
}

cotrOperators

Bash Mathematical Operators

Terminal window
# Bash Mathematical Operators:
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- Modulus (Remainder): %
- Exponentiation: **
- Increment: ((var++)) or ((var+=1))
- Decrement: ((var--)) or ((var-=1))
- Assignment: =
- Addition assignment: +=
- Subtraction assignment: -=
- Multiplication assignment: *=
- Division assignment: /=
- Modulus assignment: %=
- Exponentiation assignment: **=

cotrRead

Bash Read Input

Terminal window
read -p '${1:Prompt: }' ${2:varName}

cotrTypeCheck

Bash Type Check

Terminal window
# Bash is dynamically typed, but you can use file or grep for basic checks:
file ${1:variable} | grep -q '${2:type}'

cotrTypesInt

Bash Integer Type

Terminal window
# Bash treats integers as numeric values without decimals.

cotrPrint

Bash Print

Terminal window
echo ${1:'Your message here'}

cotrFuncLambda

Bash Lambda

Terminal window
# Bash doesn't have lambda functions.

cotrTypesDynamic

Bash Dynamic Type

Terminal window
# Bash is dynamically typed; variables can hold different types of values.

cotrTypesList

Bash List Type

Terminal window
# Bash uses arrays for lists:
myList=(item1 item2 item3)

cotrVarBool

Bash Create Boolean Variable

Terminal window
# Bash uses 0 for false and non-zero values for true:
${1:myBoolean}=${2:0}

cotrIfElse

Bash If Else Statement

Terminal window
if [ ${1:condition} ]; then
${2:// Your code here}
else
${3:// Your code here}
fi

cotrConcat

Bash Concatenate Strings

Terminal window
# Bash uses string juxtaposition for concatenation:
${1:var1}${2:var2}

cotrFuncArgsNamed

Bash Function Named Args

Terminal window
# Bash doesn't directly support named arguments, but you can simulate them using associative arrays or options parsing.

cotrGenList

Bash Generate List

Terminal window
# Bash doesn't have built-in list generation, but you can use loops or command substitution:
${1:myList}=( $(for i in {1..${2:10}}; do echo item$i; done) )

cotrNotEqual

Bash Not Equal To

Terminal window
# Bash uses '!=' for string inequality and '-ne' for numeric inequality:
[ ${1:var1} != ${2:var2} ]

cotrSwitch

Bash Switch Statement

Terminal window
case ${1:variable} in
${2:pattern1})
${3:// Your code here}
;;
${4:pattern2})
${5:// Your code here}
;;
*)
${6:// Your code here}
;;
esac

cotrOperatorsBool

Bash Boolean Operators

Terminal window
# Bash Boolean Operators:
- Logical AND: &&
- Logical OR: ||
- Logical NOT: !
- Equality: ==
- Inequality: !=
- Greater than: -gt
- Less than: -lt
- Greater than or equal to: -ge
- Less than or equal to: -le

cotrThrow

Bash Throw Exception

Terminal window
# Bash doesn't have exceptions, but you can exit with an error message:
echo "Error: ${1:Your message here}" >&2; exit 1

cotrVarNum

Bash Create Number Variable

Terminal window
# Assign a numeric value:
${1:myNumber}=${2:10}

cotrVarMap

Bash Create Map Variable

Terminal window
# Create an associative array (map):
declare -A ${1:myMap}
${1:myMap}[${2:key1}]=${3:value1}
${1:myMap}[${4:key2}]=${5:value2}

cotrVarStringMulti

Bash Create Multi-Line String Variable

Terminal window
# Use a here document for multi-line strings:
${1:myString}<<EOF
${2:Line 1}
${3:Line 2}
${4:Line 3}
EOF

cotrVarTyped

Bash Create Typed Variable

Terminal window
# Bash is dynamically typed, so variables don't have explicit types.

cotrShebang

Bash Shebang

#!/bin/bash

cotrTryCatch

Bash Try Catch

Terminal window
# Bash doesn't have try/catch, but you can use set -e and trap ERR:
set -e; trap 'echo "Error: ${1:Your message here}" >&2; exit 1' ERR; ${2:// Your code here}

cotrTypesString

Bash String Type

Terminal window
# Bash represents strings as sequences of characters.

cotrVarDate

Bash Create Date Variable

Terminal window
# Bash doesn't have a dedicated date type, but you can store date strings:
${1:myDate}=\$(date)

cotrVarList

Bash Create List Variable

Terminal window
# Create an array (list):
${1:myList}=( ${2:item1} ${3:item2} ${4:item3} )

cotrGenMap

Bash Generate Map

Terminal window
# Bash doesn't have built-in map generation, but you can use associative arrays:
declare -A ${1:myMap}; for i in {1..${2:10}}; do myMap[key$i]=value$i; done

cotrPrintMulti

Bash Print Multi

Terminal window
# Use echo with -e for multi-line output:
echo -e "${1:Line 1}\n${2:Line 2}\n${3:Line 3}"

cotrTypesMap

Bash Map Type

Terminal window
# Bash uses associative arrays for maps:
declare -A myMap; myMap[key1]=value1; myMap[key2]=value2

cotrFuncArgs

Bash Function Args

Terminal window
${2:myFunction}() {
local ${3:arg1}=${4:\$1}
local ${5:arg2}=${6:\$2}
${7:// Your code here}
}

cotrNow

Bash Date Now

Terminal window
# Get the current date and time:
now=$(date)

cotrVarNullable

Bash Create Nullable Variable

Terminal window
# Bash doesn't have null, but you can use an empty string or a special value:
${1:myVar}=${2:''}

cotrVarSyntax

Bash Variable Declaration Syntax

Terminal window
# Bash Variable Declaration Syntax:
# - varName=value: Assigns a value to a variable.
# - declare varName: Declares a variable without assigning a value.
# - readonly varName=value: Creates a read-only variable (constant).

cotrComment

Bash Comment

Terminal window
# ${1:Your comment here}

cotrEntry

Bash Entry Point

# Bash scripts typically start with the shebang line:
#!/bin/bash

cotrFuncAnon

Bash Anonymous Function

Terminal window
# Bash doesn't have true anonymous functions, but you can use function expressions:
${1:myFunction}() { ${2:// Your code here} }

cotrCase

Bash Case Statement

Terminal window
case ${1:variable} in
${2:pattern1})
${3:// Your code here}
;;
${4:pattern2})
${5:// Your code here}
;;
*)
${6:// Your code here}
;;
esac

cotrStructureFiles

Bash Project Structure (File Type)

Terminal window
# Organize source code by file type within src/:
# - src/
# - utils/
# - Contains utility functions.
# - data/
# - Contains data processing scripts.
# - tasks/
# - Contains scripts for specific tasks.
# - ... (Organize by file type)
# Note:
# - This approach can be helpful for smaller projects or specific use cases.

cotrTernary

Bash Ternary Operator

Terminal window
# Bash doesn't have a ternary operator, but you can use an if statement:
${1:condition} && ${2:trueValue} || ${3:falseValue}

cotrTypesDate

Bash Date Type

Terminal window
# Bash doesn't have a dedicated date type, but you can use the 'date' command for date manipulation.

cotrTypesNum

Bash Number Type

Terminal window
# Bash treats numbers as either integers or floating-point values.

cotrWhileLoop

Bash While Loop

Terminal window
while [ ${1:condition} ]; do
${2:// Your code here}
done

cotrFuncSyntax

Bash Function Syntax

Terminal window
# Bash Function Syntax:
function ${1:functionName} {
${2:// Your code here}
}

cotrTypesBoolTrue

Bash Boolean True

Terminal window
# Bash represents true as any non-zero value.

cotrInterpolate

Bash Interpolate String

Terminal window
# Bash uses double quotes for variable interpolation:
echo "Hello, ${1:name}!"

cotrTypesNull

Bash Null Type

Terminal window
# Bash doesn't have a dedicated null type, but you can use an empty string or a special value like 'null' to represent null.

cotrForLoop

Bash For Loop

Terminal window
for ${1:i} in ${2:list}; do
${3:// Your code here}
done

cotrEqual

Bash Equal To

Terminal window
# Bash uses '==' for string equality and '-eq' for numeric equality:
[ ${1:var1} == ${2:var2} ]

cotrForIn

Bash For…In Loop

Terminal window
for ${1:item} in ${2:list}; do
${3:// Your code here}
done