-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-manipulation
More file actions
executable file
·37 lines (27 loc) · 1.26 KB
/
Copy pathstring-manipulation
File metadata and controls
executable file
·37 lines (27 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# # removes characters from the beginning of the string
# % removes characters from the end of the string
# Single character removes smallest matching string
# Double characters removes longest matching string
fullString="This is my full string"
echo "fullString=\"$fullString\""
# Remove all chacaters from the start of the string to the first space character
# i.e. Show all but first word
echo "\${fullString#* }=\"${fullString#* }\""
# Remove all characters from the start of the string to the last space character
# i.e Get last word
echo "\${fullString##* }=\"${fullString##* }\""
# Remove all characters from the end of the string to the first space character (from the end)
# i.e. Get all but last word
echo "\${fullString% *}=\"${fullString% *}\""
# Remove all characters from the end of the line to the last space character (from the end)
# i.e. Get first word
echo "\${fullString%% *}=\"${fullString%% *}\""
# Remove "full" from the string
echo "\${fullString/full}=\"${fullString/full}\""
# Replace "my" with "your"
echo "\${fullString/my/your}=\"${fullString/my/your}\""
# Replaces first space character with colon
echo "\${fullString/ /:/}=\"${fullString/ /:}\""
# Replace ALL space characters with colon
echo "\${fullString// /:/}=\"${fullString// /:}\""