latest pushes

This commit is contained in:
2024-10-05 11:54:36 -04:00
parent 482ffe0604
commit b0a2610d70
8 changed files with 43 additions and 123 deletions

View File

@ -5,41 +5,41 @@
# Addition
result=$((5 + 3))
echo Addition: 5 + 3 = $result
echo Addition: "5 + 3 =" $result
# Subtraction
result=$((10 - 4))
echo Subtraction: 10 - 4 = $result
echo Subtraction: "10 - 4 =" $result
# Multiplication
result=$((6 * 7))
echo Multiplication: 6 * 7 = $result
echo Multiplication: "6 * 7 =" $result
# Division
result=$((20 / 4))
echo Division: 20 / 4 = $result
echo Division: "20 / 4 =" $result
# Modulus
result=$((17 % 5))
echo Modulus: 17 % 5 = $result
echo Modulus: "17 % 5 =" $result
# Compound operation
result=$(( (10 + 5) * 2 ))
echo Compound: (10 + 5) * 2 = $result
echo Compound: "(10 + 5) * 2 =" $result
# Using variables
a=7
b=3
result=$((a + b))
echo Variables: $a + $b = $result
echo Variables: "$a + $b =" $result
# Increment
count=0
count=$((count + 1))
echo Increment: count after increment = $count
echo Increment: count after increment "=" $count
# Decrement
count=$((count - 1))
echo Decrement: count after decrement = $count
echo Decrement: count after decrement "=" $count
echo Basic math operations completed.

View File

@ -5,27 +5,27 @@
# Create a test file
echo "Creating test file..."
echo "Hello, World!" > test.txt
write test.txt "Hello, World!"
# Read the contents of the file
echo "\nReading test file:"
cat test.txt
read test.txt
# Append to the file
echo "\nAppending to test file..."
echo "This is a new line" >> test.txt
append test.txt "This is a new line"
# Read the updated contents
echo "\nReading updated test file:"
cat test.txt
read test.txt
# Write to a new file
echo "\nWriting to a new file..."
echo "This is a new file" > new_file.txt
write new_file.txt "This is a new file"
# Read the new file
echo "\nReading new file:"
cat new_file.txt
read new_file.txt
# List files in the current directory
echo "\nListing files in the current directory:"
@ -35,26 +35,6 @@ ls -l
echo "\nRenaming file..."
mv new_file.txt renamed_file.txt
# Check if file exists
echo "\nChecking if files exist:"
if [ -f "test.txt" ]; then
echo "test.txt exists"
else
echo "test.txt does not exist"
fi
if [ -f "new_file.txt" ]; then
echo "new_file.txt exists"
else
echo "new_file.txt does not exist"
fi
if [ -f "renamed_file.txt" ]; then
echo "renamed_file.txt exists"
else
echo "renamed_file.txt does not exist"
fi
# Delete files
echo "\nDeleting files..."
rm test.txt renamed_file.txt

View File

@ -5,7 +5,7 @@
# Simple function
function greet() {
echo "Hello, $1!"
echo Hello
}
echo "Testing simple function:"

View File

@ -6,31 +6,32 @@
# String concatenation
first_name=John
last_name=Doe
full_name=$first_name $last_name
full_name="$first_name $last_name"
echo Full name: $full_name
# String length
string="Hello, World!"
echo "The string '$string' has ${#string} characters."
echo The string '$string' has ${#string} characters.
# Substring extraction
echo "The first 5 characters are: ${string:0:5}"
echo The first 5 characters are: ${string:0:5}
# String replacement
sentence="The quick brown fox jumps over the lazy dog"
echo "Original sentence: $sentence"
echo Original sentence: $sentence
new_sentence=${sentence/fox/cat}
echo "Modified sentence: $new_sentence"
echo Modified sentence: $new_sentence
# Converting to uppercase and lowercase
echo "Uppercase: ${string^^}"
echo "Lowercase: ${string,,}"
echo Uppercase: ${string^^}
echo Lowercase: ${string,,}
# Trimming whitespace
padded_string=" trim me "
echo "Original string: '$padded_string'"
trimmed_string=${padded_string## }
trimmed_string=${trimmed_string%% }
echo "Trimmed string: '$trimmed_string'"
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'
echo "String manipulation operations completed."
# Completion message
echo String manipulation operations completed.