bananas0102
bananas0102

Reputation: 1

Echo in bash is replacing first letter/character with the last when pulling from array

I made a simple script in bash that asks "What would you like to $action?". The action variable should be replaced with user's choice on each loop. This seems to work, but the issue is that the last character which is the question mark (?) is replacing the first character which is "W". I looked around and couldn't find anything related to why this happens.

I tried this with cygwin and Ubuntu, getting the same issue.

Here is the code

#!/bin/bash

readOptions () {
ed -s "do.csv" <<EOF
,p
q
EOF
}

action="do"

echo "You can press 'q' anytime to exit!"

while [ ! action = "q" ] 
do

echo "What would you like to $action?"

option=$(readOptions)

echo "$option"

read action

chose_opt=( $option ) 
action=${chose_opt[$action]}

done

Here is the output

enter image description here

The echo should display "What would you like to add?"

Upvotes: 0

Views: 29

Answers (0)

Related Questions