Technical issues/questions of an intermediate or advanced nature.
-
Ed_P
- Contributor
![Contributor Contributor](./images/ranks/contributor.gif)
- Posts: 8368
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#1
by Ed_P » 28 Mar 2021, 18:46
This code.
Code: Select all
:
:
g3=space_invaders
echo
echo 1. $g1
echo
echo 2. $g2
echo
echo 3. $g3
echo
read -p "Select 1, 2 or 3: " Nbr
Game="$""g"$Nbr
echo Game=$Game
echo $Game
echo "$g"$Nbr
echo $g3
read
The output.
Code: Select all
:
:
3. space_invaders
Select 1, 2 or 3: 3
Game=$g3
$g3
3
space_invaders
When 3 is selected how do I get the " echo $Game " or " echo "$g"$Nbr " results to be the same as the " echo $g3 " result? " echo $g$Nbr " doesn't work either.
![Unknown :unknown:](./images/smilies/unknw.gif)
Ed
Ed_P
-
burdi01
- Shogun
![Shogun Shogun](./images/ranks/SilverStar5.png)
- Posts: 206
- Joined: 18 Aug 2013, 12:09
- Distribution: Slackware PartedMagic Xubuntu
- Location: The Netherlands
Post#2
by burdi01 » 29 Mar 2021, 10:22
burdi01
-
ncmprhnsbl
- DEV Team
![DEV Team DEV Team](./images/ranks/devteam.gif)
- Posts: 3936
- Joined: 20 Mar 2012, 03:42
- Distribution: v5.0-64bit
- Location: australia
-
Contact:
Post#3
by ncmprhnsbl » 29 Mar 2021, 13:35
that
or a different aproach:
use an array:
Code: Select all
g=(one two three)
echo
echo 1. ${g[0]}
echo
echo 2. ${g[1]}
echo
echo 3. ${g[2]}
echo
read -p "Select 1, 2 or 3: " Nbr
echo Game=${g[$Nbr-1]}
output:
Code: Select all
1. one
2. two
3. three
Select 1, 2 or 3: 3
Game=three
or to avoid the -1 part, have a 'dummy' first array entry(zero) that isn't used
Code: Select all
g=(zero one two three)
echo
echo 1. ${g[1]}
echo
echo 2. ${g[2]}
echo
echo 3. ${g[3]}
echo
read -p "Select 1, 2 or 3: " Nbr
echo Game=${g[$Nbr]}
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44
ncmprhnsbl
-
Ed_P
- Contributor
![Contributor Contributor](./images/ranks/contributor.gif)
- Posts: 8368
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#4
by Ed_P » 29 Mar 2021, 14:51
ncmprhnsbl wrote: ↑29 Mar 2021, 13:35
that
or a different aproach:
use an array:
Wow!! Thank you guys.
A related question, how can I start an app with the script and allow the terminal window to close while the app runs? Now when the terminal window closes so too does the app it starts. The app is Adobe's flashplayer.
Ed
Ed_P
-
ncmprhnsbl
- DEV Team
![DEV Team DEV Team](./images/ranks/devteam.gif)
- Posts: 3936
- Joined: 20 Mar 2012, 03:42
- Distribution: v5.0-64bit
- Location: australia
-
Contact:
Post#5
by ncmprhnsbl » 29 Mar 2021, 23:06
Ed_P wrote: ↑29 Mar 2021, 14:51
how can I start an app with the script and allow the terminal window to close while the app runs?
disown:
Code: Select all
<command> &
disown
or
<command> &; disown
or
<command> & disown
or
nohup <command> & disown
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44
ncmprhnsbl
-
Ed_P
- Contributor
![Contributor Contributor](./images/ranks/contributor.gif)
- Posts: 8368
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#6
by Ed_P » 30 Mar 2021, 01:24
Wow!
I learn a thing or two by seeing what others post and by asking questions but to learn
4 new things in one thread is unbelievable.
eval
disown
nohup
and an easy array
![Surprised :o](./images/smilies/ohmy.gif)
All in a simple script to play some old games.
Thank you
ncmprhnsbl and
burdi01.
Added in 1 day 15 hours 18 minutes 58 seconds:
This works and I can close the terminal window and flashplayer stays open.
Code: Select all
nohup ./flashplayer $Game > /dev/null 2>&1 &
disown
echo " "
echo " Hope you have fun."
read
But if I remove the "read" or replace it with "exit" flashplayer doesn't even start when run from a nemo Run in Terminal prompt or .desktop file.
![Sad :(](./images/smilies/sad.gif)
But in terminal mode it starts and the script ends as desired.
![Crazy :crazy:](./images/smilies/crazy.gif)
Ed
Ed_P
-
Ed_P
- Contributor
![Contributor Contributor](./images/ranks/contributor.gif)
- Posts: 8368
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#7
by Ed_P » 04 Apr 2021, 04:59
This works.
Code: Select all
nohup ./flashplayer $Game > /dev/null 2>&1 &
disown
echo " "
echo " Hope you have fun."
sleep 3
exit
Ed
Ed_P