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)
CodePudding user response:
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