0

I'm trying to write a script using the "Select" command; this works fine, except it lists each option broken into two (Example below).

Also, please bear with me as I am new to this.

Here's the script (The script is not complete):

select profile in $(cat ~/PROFILEFILE | grep -i profile); do
echo $REPLY $profile
done

In this file, there is a list of AWS profiles; for example, [PROFILE XYZ19273].

Running the script lists the options, but the output is as follows.

1)PROFILE

2)XYZ19273

I was expecting something like this.

  1. PROFILE XYZ19273

How can I make this work? Any tips or feedback is appreciated.


Thank you @tripleee, your comments helped me and pointed me in the right direction. Just in case anyone stumbles on this question. I followed what @wisecracker suggested about using IFS here. I Got rid of the useless cat as well.

TSBe
  • 1
  • 1
  • The command substitution emits a number of tokens and that's what `select` operates on. You will probably want to surround the lines with quotes, and/or populate an array from the file. Without seeing what's in the file, we are sort of operating in the blind; this is a common FAQ anyway (in its simplest form [When to wrap quotes around a shell variable?](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) but I'm hesitant to mark as a duplicate of that). ... – tripleee Nov 05 '22 at 11:54
  • ... Perhaps see also https://mywiki.wooledge.org/BashFAQ/020 which is however discussing file names, not strings in general. You'll also separately want to get rid of the [useless `cat`](https://stackoverflow.com/questions/11710552/useless-use-of-cat). – tripleee Nov 05 '22 at 11:55

0 Answers0