Advertisement
SimpleCookie

Untitled

Jan 11th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Function to process each element
  4. process_element() {
  5.     local element="$1"
  6.    
  7.     # Your processing logic here
  8.     # Example: Check if the length of the element is greater than 3
  9.     if [ ${#element} -gt 3 ]; then
  10.         return 0  # Return 0 if the element should be removed
  11.     else
  12.         return 1  # Return 1 if the element should be kept
  13.     fi
  14. }
  15.  
  16. # List of elements
  17. my_list=("apple" "banana" "cherry" "date" "elderberry")
  18.  
  19. # Loop until the list is empty
  20. while [ ${#my_list[@]} -gt 0 ]; do
  21.     # Call the function for each element
  22.     for element in "${my_list[@]}"; do
  23.         if process_element "$element"; then
  24.             echo "Removing: $element"
  25.             my_list=("${my_list[@]/$element}")  # Remove the element from the list
  26.         else
  27.             echo "Keeping: $element"
  28.         fi
  29.     done
  30. done
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement