🔧 Programmierung5 Useful Python Scripts to Automate CSV Processing(10.09.2026 um 14:00 Uhr)
🔧 Programmierung5 Python Techniques for Efficient Resource Orchestration(11.09.2026 um 14:00 Uhr)
🔧 ProgrammierungFrom Spaghetti Code to Clean Python: A Beginner’s Guide(11.09.2026 um 16:00 Uhr)
🔧 ProgrammierungText Watermarking in Python: Catch Whoever Copies Your Writing(06.09.2026 um 16:00 Uhr)
🔧 ProgrammierungWhy Most Multi-Agent Systems Fail Even When Evaluation Passes(07.09.2026 um 14:00 Uhr)
🔧 ProgrammierungA Beginner’s Guide to World Models(08.09.2026 um 19:27 Uhr)
🔧 Programmierung7 Async Patterns for Running Agents Concurrently in Python(11.08.2026 um 14:00 Uhr)
🔧 ProgrammierungManaging Small Context Windows in Language Models(18.08.2026 um 14:00 Uhr)
🔧 Programmierung5 Useful Python Scripts to Automate CSV Processing(10.09.2026 um 14:00 Uhr)
🔧 Programmierung5 Python Techniques for Efficient Resource Orchestration(11.09.2026 um 14:00 Uhr)
🔧 ProgrammierungFrom Spaghetti Code to Clean Python: A Beginner’s Guide(11.09.2026 um 16:00 Uhr)
🔧 ProgrammierungText Watermarking in Python: Catch Whoever Copies Your Writing(06.09.2026 um 16:00 Uhr)
🔧 ProgrammierungWhy Most Multi-Agent Systems Fail Even When Evaluation Passes(07.09.2026 um 14:00 Uhr)
🔧 ProgrammierungA Beginner’s Guide to World Models(08.09.2026 um 19:27 Uhr)
🔧 Programmierung7 Async Patterns for Running Agents Concurrently in Python(11.08.2026 um 14:00 Uhr)
🔧 ProgrammierungManaging Small Context Windows in Language Models(18.08.2026 um 14:00 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 3 Min Lesezeit
0

A Month With Bash — Part 2: Expansions

↗ Quelle (dev.to)
🗣️ Stimme:




A Month With Bash — Part 2: Expansions



Continuing from where I left off, the next thing I learned was special parameters in bash:




  • "$*"

  • $#

  • $?

  • $@

  • $N

  • $-

  • $0



Another important concept I picked up is how bash executes shell scripts. Bash is one of those languages that interprets each line as it goes — but it doesn't stop if a line fails. It continues on unless you explicitly set set -o pipefail (or -e, depending on what you want it to catch).



Generally, the procedure looks like this:



Tokenizing: splitting the line into tokens, usually split using the IFS value.



Brace expansion: a mechanism by which arbitrary strings can be generated.




CODE
echo file{1,2,3}.txt
## output: file1.txt file2.txt file3.txt






Bash preserves the order from left to right.



Tilde expansion: this is where expansion of special symbols takes place.





  • ~ represents the HOME built-in variable


  • ~+ represents PWD, the current working directory

  • and others




CODE
DIR=~/Desktop # this is $HOME/Desktop
echo "$DIR"






Parameter expansion: introduced with the $ symbol.




CODE
# ${} — the braces can be omitted for normal variables but not for array-type variables






Command substitution: very important — it lets you assign the output of a command to a variable, and use commands inside if and for statements. Done with $(command to execute).




CODE
week_name="$(date +%A)" # gets the current day of the week
echo "$week_name"






Generally, $() spawns a new shell instance, so it's advisable to avoid it where possible, for latency reasons.



Arithmetic expansion: just from the name, this allows evaluation of arithmetic expressions and substitution of the result. It starts with $(( expression )). There are some rules — bash doesn't support floating point arithmetic natively, so you'd reach for bc if you need it. I won't go deep into that here since this isn't a full bash tutorial.



Here's a simple BMI calculator I wrote while practicing this:




CODE
#!/usr/bin/env bash

# script calculates user's BMI and gives a recommendation

set -euo pipefail

# ---------------- read parameters ----------------
weight="$1"
height="$2"

bmi=$(bc -q <<< "scale=2; $weight / ($height^2)")

# ---------------- test ----------------
if (( $(bc -q <<< "$bmi < 18.5") )); then
echo "UNDERWEIGHT"
elif (( $(bc -q <<< "$bmi < 25") )); then
echo "normal weight"
elif (( $(bc -q <<< "$bmi < 30") )); then
echo "overweight"
else
echo "obese"
fi






Process substitution: this saves the output of a process into a temporary file-like descriptor under /dev/fd/N. It lets you feed command output into programs that expect a file as input. Done with >(command) and <(command).




CODE
#!/usr/bin/env bash

# script demonstrates process substitution
# process substitution is when you want to use the output of a command
# as the input to a command that needs files as parameters

set -euo pipefail

# gets the difference between two texts without making temp files
echo "$(diff -p <(echo "hello mr beast") <(echo "hello mr beast."))"

# note: <(cmd) uses the output of a command as a file
# >(cmd) takes input from a program and feeds it to the command as a file






Word splitting and globbing: occurs after expansion, only on unquoted values.



Next up: regex, grep/sed/awk, and moving into building actual projects.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
5 Useful Python Scripts to Automate CSV Processing
1 Quelle
5 Python Techniques for Efficient Resource Orchestration
1 Quelle
From Spaghetti Code to Clean Python: A Beginner’s Guide