Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Function to process each element
- process_element() {
- local element="$1"
- # Your processing logic here
- # Example: Check if the length of the element is greater than 3
- if [ ${#element} -gt 3 ]; then
- return 0 # Return 0 if the element should be removed
- else
- return 1 # Return 1 if the element should be kept
- fi
- }
- # List of elements
- my_list=("apple" "banana" "cherry" "date" "elderberry")
- # Loop until the list is empty
- while [ ${#my_list[@]} -gt 0 ]; do
- # Call the function for each element
- for element in "${my_list[@]}"; do
- if process_element "$element"; then
- echo "Removing: $element"
- my_list=("${my_list[@]/$element}") # Remove the element from the list
- else
- echo "Keeping: $element"
- fi
- done
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement