0

I would like to create a bash script so I can select a server I can connect to using mosh. Currently I have this small script that shows me the username and ip of the server. Its difficult to remember what server does what so I would like to add some remark to the ip.

How could I modify it in such way that it also shows me a label or remark to the menu entry so its easier for me to identify the server.

Currently it looks like this:

#!/bin/bash

PS3='Pick a server (or ctrl-c to quit): '
select item in \
"username@someip" \
"username@someip" \
"username@someip" \
"username@someip" \
"username@someip" \
"username@someip"
do
               mosh $item
exit 0
done

which creates the following menu:

1) username@someip  3) username@someip  5) username@someip
2) username@someip  4) username@someip  6) username@someip

how could I modify this script so it creates the following menu:

1) username@someip (some remark) 3) username@someip (some remark)   5) username@someip (some remark)
2) username@someip (some remark) 4) username@someip (some remark)   6) username@someip (some remark)
3
  • 1
    ?? "username@someip (some remark)" \ "username@someip (some remark)" \ ? Commented Jan 3, 2022 at 14:29
  • this will not work because it results in 'mosh username@someip (some remark)' Commented Jan 3, 2022 at 14:32
  • Then: do not use select and write your own printing and reading functinality, or filter (some remark) from $item. Commented Jan 3, 2022 at 14:34

1 Answer 1

1

Learn (Parameter Expansion Rules)[https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html]

#!/bin/bash
PS3='Pick a server (or ctrl-c to quit): '
select item in "u1@ip1 (foo)" "u1@ip2 (bar)" "u2@ip1 (baz)" "u2@ip2 (foo bar)" 
do mosh "${item%% *}" # strips the unwanted part
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.