KandZ – Tuts

We like to help…!

Linux CLI 65 ๐Ÿง Parameter expansion in shell scripts

a - what is parameter expasion in shell scripts part 1
Parameter expansion in a shell script allows you to manipulate variable values in various ways...
such as substring extraction, default value assignment, and pattern replacement.
common parameter expansions:
1. Substring Extraction:
${variable:position} โ†’ Extracts the substring from the specified position to the end.
${variable:position:length} โ†’ Extracts a substring of the specified length starting from the given position.
2. Default Value Assignment:
${parameter:-word}} โ†’ If parameter is unset or null, use word.
${parameter:=word} โ†’ If parameter is unset or null, assign it the value word.
3. Parameter Replacement:
${parameter+word} โ†’ If parameter is set, use word; otherwise, use an empty string.
${parameter?word} โ†’ If parameter is set, use its value; otherwise, print an error message and exit.

b - what is parameter expasion in shell scripts part 2
4. Length of a Parameter:
${#variable} โ†’ Returns the length of the variable.
5.Pattern Replacement:
${parameter/pattern/string} โ†’ Replaces the first occurrence of pattern with string.
${parameter//pattern/string} โ†’ Replaces all occurrences of pattern with string.
6. Remove Matching Prefix/Suffix:
${parameter#pattern} โ†’ Removes the shortest matching prefix.
${parameter##pattern} โ†’ Removes the longest matching prefix.
${parameter%pattern} โ†’ Removes the shortest matching suffix.
${parameter%%pattern} โ†’ Removes the longest matching suffix.

Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO