latest pushes

This commit is contained in:
2024-10-15 22:47:29 -04:00
parent 8f087db1b8
commit 14e5a2043d
8 changed files with 246 additions and 280 deletions

0
bellos_scripts/basic_math.bellos Normal file → Executable file
View File

View File

@ -1,54 +1,52 @@
#!/usr/bin/env bellos
# File: control_structures.bellos
# Demonstrating if statements and loops
# If-else statement
echo "If-else statement:"
# Demonstrating if-else statements
echo "Demonstrating if-else statements:"
x=10
if [ $x -gt 5 ]; then
If [ $x -gt 5 ] Then
echo "x is greater than 5"
else
Else
echo "x is not greater than 5"
fi
Fi
# Nested if-else
echo "\nNested if-else:"
# Demonstrating nested if-else
echo "Demonstrating nested if-else:"
y=20
if [ $x -gt 5 ]; then
if [ $y -gt 15 ]; then
If [ $x -gt 5 ] Then
If [ $y -gt 15 ] Then
echo "x is greater than 5 and y is greater than 15"
else
Else
echo "x is greater than 5 but y is not greater than 15"
fi
else
Fi
Else
echo "x is not greater than 5"
fi
Fi
# While loop
echo "\nWhile loop:"
# Demonstrating while loop
echo "Demonstrating while loop:"
counter=0
while [ $counter -lt 5 ]; do
While [ $counter -lt 5 ] Do
echo "Counter: $counter"
counter=$((counter + 1))
done
Done
# For loop
echo "\nFor loop:"
for i in 1 2 3 4 5; do
# Demonstrating for loop
echo "Demonstrating for loop:"
For i In 1 2 3 4 5 Do
echo "Iteration: $i"
done
Done
# For loop with range
echo "\nFor loop with range:"
for i in $(seq 1 5); do
# Demonstrating for loop with command substitution
echo "Demonstrating for loop with command substitution:"
For i In $(seq 1 5) Do
echo "Number: $i"
done
Done
# Case statement
echo "\nCase statement:"
# Demonstrating case statement
echo "Demonstrating case statement:"
fruit="apple"
case $fruit in
Case $fruit In
"apple")
echo "It's an apple"
;;
@ -61,4 +59,14 @@ case $fruit in
*)
echo "Unknown fruit"
;;
esac
Esac
# Demonstrating function
echo "Demonstrating function:"
Function greet (
echo "Hello, $1!"
)
greet "World"
greet "Bellos"
echo "Control structures demonstration completed."

0
bellos_scripts/file_operations.bellos Normal file → Executable file
View File

65
bellos_scripts/string_manipulation.bellos Normal file → Executable file
View File

@ -1,37 +1,54 @@
#!/usr/bin/env bellos
# File: string_manipulation.bellos
# Demonstrating basic string manipulation in Bellos
# Demonstrating string manipulation
# String concatenation
# String assignment
echo "String assignment:"
first_name=John
last_name=Doe
full_name="$first_name $last_name"
echo Full name: $full_name
echo "first_name: $first_name"
echo "last_name: $last_name"
echo
# String length
string="Hello, World!"
echo The string '$string' has ${#string} characters.
# String concatenation
echo "String concatenation:"
full_name="$first_name $last_name"
echo full_name: $full_name
echo
# Substring extraction
echo The first 5 characters are: ${string:0:5}
# Using strings in commands
echo "Using strings in commands:"
greeting=Hello
echo "$greeting, $full_name!"
echo
# String replacement
# Quoting strings
echo "Quoting strings:"
sentence="The quick brown fox jumps over the lazy dog"
echo Original sentence: $sentence
new_sentence=${sentence/fox/cat}
echo Modified sentence: $new_sentence
echo With double quotes: "$sentence"
echo With single quotes: '$sentence'
echo
# Converting to uppercase and lowercase
echo Uppercase: ${string^^}
echo Lowercase: ${string,,}
# Assigning command output to a variable
echo "Assigning command output to a variable:"
current_date=10-17-2025
echo "The current date is: $current_date"
echo
# Trimming whitespace
padded_string=" trim me "
echo Original string: '$padded_string'
trimmed_string="${padded_string#"${padded_string%%[![:space:]]*}"}" # Trim leading whitespace
trimmed_string="${trimmed_string%"${trimmed_string##*[![:space:]]}"}" # Trim trailing whitespace
echo Trimmed string: '$trimmed_string'
# Escaping special characters
echo "Escaping special characters:"
path=/home/user/documents
echo "Path with slashes: $path"
echo "Dollar sign: $100"
echo
# Using variables in paths
echo "Using variables in paths:"
username=johndoe
user_home=/home/$username
echo "User's home directory: $user_home"
echo
# Completion message
echo String manipulation operations completed.
echo "String manipulation operations completed."