#askpietro

Home Archives
2025-09-30 Pietro Martinelli
bash

BASH gotchas - Episode 0

Extracting substrings

1
2
3
4
5
a="abcdefghi"
echo ${a}
echo ${a:5:2}
echo ${a:8:4}
# ${variable_name:0-based index:length}

Default value for variables

1
2
3
4
5
a="abcdefghi"
echo ${a:-foobar}
echo ${b:-foobar}
echo ${c:-${b:-foobar}}
# ${variable_name:-default_expression}
Share
  • bash
  • scripting
  • shell
Newer
BASH gotchas - Episode 1 - git prompt
Older
Testing and shell-scripting reloaded: bash-unit

Categories

  • antipatterns2
  • bash2
  • coding horrors3
  • design patterns5
  • devops1
  • functional programming4
  • kotlin1
  • please don't...3
  • scala1
  • solid1
  • testing4
    • java1
  • toolbox1

Tags

  • antipatterns4
  • automation1
  • bash8
  • c#2
  • code3
  • coding horrors5
  • console1
  • csharp2
  • database1
  • dependency inversion1
  • design6
  • design patterns6
  • devops1
  • dsl2
  • functional programming4
  • git1
  • gof1
  • how-to1
  • java6
  • javaee1
  • javascript3
  • job1
  • k8s1
  • kotlin1
  • kubernetes1
  • me2
  • microservices1
  • mocking2
  • modelling1
  • patterns1
  • reinventing the wheel1
  • scala1
  • scripting8
  • shell4
  • singleton1
  • solid1
  • tdd3
  • testing5
  • vagrant1
  • violations1

Tag Cloud

antipatterns automation bash c# code coding horrors console csharp database dependency inversion design design patterns devops dsl functional programming git gof how-to java javaee javascript job k8s kotlin kubernetes me microservices mocking modelling patterns reinventing the wheel scala scripting shell singleton solid tdd testing vagrant violations

Archives

  • 20252
  • 20235
  • 20223
  • 20216
  • 20203
  • 20191
  • 20181
  • 20151
  • 20141
  • 20128

Recent Posts

  • BASH gotchas - Episode 1 - git prompt
  • BASH gotchas - Episode 0
  • Testing and shell-scripting reloaded: bash-unit
  • How to setup a Kubernetes cluster on virtual machines through Vagrant and Microk8s
  • JavaScript proxies: a simple factory for memoized functions

Pages

  • About me
© 2025 Pietro Martinelli
Powered by Hexo
Home Archives