Skip to content

Commit ecc58f8

Browse files
authored
operation on scalar variables
1 parent 7aff4dc commit ecc58f8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

learningbash.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,16 @@
134134
```
135135
- to interpret special characters: `echo -e "This is \n a new line"`
136136
- to disable new line trailing special characters: `echo -n "This line will not be followed by a new line"`
137-
137+
138+
### operation on scalar variables:
139+
140+
```
141+
sentence="today is sunday"
142+
echo ${#sentence} //will print 4
143+
echo ${#sentence:2} //will print day is sunday
144+
echo ${#sentence:2:3} //will print day
145+
echo ${#sentence:-zaki} //will print zaki if sentence wasn't defined or empty.
146+
echo ${#sentence:=zaki} //will print zaki if sentence wasn't defined or empty+ the sentence variable will be initializaed with "zaki" as value.
147+
echo ${#sentence:+zaki} //will print zaki, sentence will be initializaed wit the zaki value if it was defined and wasn't empty.
148+
149+
```

0 commit comments

Comments
 (0)