latest pushes

This commit is contained in:
Ronaldson Bellande 2024-09-24 18:39:42 -04:00
parent 5eb03315b7
commit 04f8340376
6 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#!/usr/bin/env bellos
# File: file_operations.bellos
# Demonstrating file operations
# Writing to a file
echo "This is a test file" > test.txt
echo "Adding another line" >> test.txt
# Reading from a file
echo "Contents of test.txt:"
cat test.txt
# Using a while loop to read file line by line
echo "Reading file line by line:"
while read -r line
do
echo "Line: $line"
done < test.txt
# Cleaning up
rm test.txt

View File

@ -0,0 +1,31 @@
#!/usr/bin/env bellos
# File: control_structures.bellos
# Demonstrating if statements and loops
# If statement
if [ $# -eq 0 ]
then
echo "No arguments provided"
elif [ $# -eq 1 ]
then
echo "One argument provided: $1"
else
echo "Multiple arguments provided"
fi
# For loop
echo "Counting from 1 to 5:"
for i in 1 2 3 4 5
do
echo $i
done
# While loop
echo "Countdown:"
count=5
while [ $count -gt 0 ]
do
echo $count
count=$((count - 1))
done

View File

@ -0,0 +1,23 @@
#!/usr/bin/env bellos
# File: file_operations.bellos
# Demonstrating file operations
# Writing to a file
echo "This is a test file" > test.txt
echo "Adding another line" >> test.txt
# Reading from a file
echo "Contents of test.txt:"
cat test.txt
# Using a while loop to read file line by line
echo "Reading file line by line:"
while read -r line
do
echo "Line: $line"
done < test.txt
# Cleaning up
rm test.txt

View File

@ -0,0 +1,17 @@
#!/usr/bin/env bellos
# File: functions.bellos
# Defining and using functions
function greet() {
echo "Hello, $1!"
}
function add() {
echo $(($1 + $2))
}
# Calling functions
greet "User"
result=$(add 3 4)
echo "3 + 4 = $result"

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bellos
# File: hello_world.bellos
# Simple Hello World script
echo "Hello, World!"
# Using variables
name="Bellos"
echo "Welcome to $name programming!"

View File

@ -0,0 +1,23 @@
#!/usr/bin/env bellos
# File: string_manipulation.bellos
# Demonstrating string manipulation
string="Hello, Bellos!"
# String length
echo "Length of string: ${#string}"
# Substring
echo "First 5 characters: ${string:0:5}"
# String replacement
new_string=${string/Bellos/World}
echo "Replaced string: $new_string"
# Converting to uppercase
echo "Uppercase: ${string^^}"
# Converting to lowercase
echo "Lowercase: ${string,,}"