Solution to reverse string in Bash

This commit is contained in:
2023-05-16 19:57:08 +02:00
parent 2ca6833ba9
commit bcfff775dc
7 changed files with 881 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
input=$1
reversed=""
length=${#input}
for (( i=$length-1; i>=0; i-- )); do
# extract each character from input
# and append it to reversed
reversed="${reversed}${input:$i:1}"
done
echo "$reversed"