gpt-4o-2024-05-13· OpenAI
WildChat-4.8M (AI2)
Develop a bash script that takes a string as an argument and returns its reverse…
- User
Develop a bash script that takes a string as an argument and returns its reverse version, changing uppercase letters to lowercase and back
- Assistant
Sure, I can help you develop a Bash script that performs the string reversal and character case change as described. Here is a simple script that does that:
bash#!/bin/bash # Function to reverse the string and change case reverse_and_change_case() { input_string="$1" # Reverse the string reversed_string=$(echo "$input_string" | rev) # Change uppercase to lowercase and vice versa modified_string=$(echo "$reversed_string" | awk '{ for (i=1; i<=length; i++) { c=substr($0, i, 1); if (c ~ /[a-z]/) printf toupper(c); else if (c ~ /[A-Z]/) printf tolower(c); else printf c; }; printf "\n"; }') echo "$modified_string" } # Check if an argument is provided if [ -z "$1" ]; then echo "Usage: $0 <string>" exit 1 fi # Call the function with the provided argument reverse_and_change_case "$1"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.