0

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?"

  • Please paste your script at [shellcheck.net](http://www.shellcheck.net/) and try to implement the recommendations made there. – Cyrus Mar 17 '23 at 23:07
  • 2
    I suggest: `dos2unix do.csv` – Cyrus Mar 17 '23 at 23:35
  • Something here has DOS/Windows line endings, but I'm not clear on which file it is. See ["Are shell scripts sensitive to encoding and line endings?"](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) for info on how to detect & fix this. – Gordon Davisson Mar 18 '23 at 00:07

0 Answers0