Skip to content

Bash Main

Docs

Seitng up defualt values with :

set default values for variables without performing any action

: ${VAR:=default_value}```


## Bash string manipulation  

> **Perom  replacment**
```bash 
# ${parameter/pattern/string}
 selected="my_session:123:456"
session_name="${selected//:/-}"
echo $session_name  # Output: my_session-123-456

Delte from match to the end

# %% to find the longest possilbe match 
session_name="${selected%%:*}"

Checking if the output was from stdin or as cmd args

if [[  -t 0  ]]; then 
    printf "this was provided from cmd args\n"
fi

if [[  ! -t 0  ]]; then 
    printf "this was provided from pipe\n"
fi 

Printitn mulitple values

printf -v sep  '%.0s-' {1..15};)

Checking the lenght of the array

${#parameter}

Tip

Functions are the only way to change status of an existing shell

Fucntions

Case stament
While loop

Variables

Bash redirecition

[xargs_commnad]({{\< ref “posts/code_snippets/xargs_commnad.md”>}})