Skip to content

Instantly share code, notes, and snippets.

@ellcs
Last active May 11, 2020 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellcs/9e21c9963094a1b0dac3095afdc340aa to your computer and use it in GitHub Desktop.
Save ellcs/9e21c9963094a1b0dac3095afdc340aa to your computer and use it in GitHub Desktop.
# gleiche zuweisung
var1=abc
var2="abc"
echo "$var1"
echo "$var2"
# string mit spaces
var3="abc def"
var4=abc\ def
echo "$var3"
echo "$var4"
# single quotes, wenn variablen nicht interpretiert werden sollen, wenn du also
im_am_a_var="martion ist 1 cuter boi"
echo '$im_am_a_var' # aquivalent zu
echo "\$im_am_a_var"
# um den namen einer variable zu "beschränken", benutzt du ${}.
# in zeile 23 ist die verwendete variable im_am_a_varasdf.
echo "hello$im_am_a_varasdf"
echo "hello${im_am_a_var}asdf"
# am besten verwendest du einfach immer string + ${}
echo "hello${im_am_a_var}asdf"
# tätsächlich kann das auch eine sicherheitslücke werden, wenn du es nicht in
# einen string wirfst. Probier dies
echo -e "import sys\nprint(len(sys.argv))\nprint(sys.argv)" > test_argv.py
python test_argv.py asdf asdf asdf
# Wenn eine varible keinen wert hat und nicht in einem string ist, reduziert
# sich argv. das kann tatsächlich zu sicherheitsproblemen führen :D
# erwarteter output: ['test_argv.py', 'asdf', '', 'asdf']
# tatsächlicher output: ['test_argv.py', 'asdf', 'asdf']
python test_argv.py asdf $non_existet asdf
# damit das nicht passiert, die variable immer in einen string werfen:
python test_argv.py asdf "$non_existet" asdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment