LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2016, 07:48 AM   #1
frizzant
LQ Newbie
 
Registered: Jul 2016
Posts: 2

Rep: Reputation: Disabled
Post Simple Shell Script - Debian 8


Hello lovelies!

I am trying to get a very simple shell script to work. But somehow it never works how i want it to.

So i enter minecraft_starter, the script starts. Now i want to enter minecraft_starter gui, so the elif with the variable gui starts. But it doesn't. I am sure it is pretty simple. Thing is i cant figure it out. And Yes I asked google for the last two hours .

minecraft_starter:
Code:
#!/bin/bash

if [ "$output" ]
                then java -Xmx3896M -Xms1G -d64 -jar /home/minecraft/minecraft-server/minecraft_server.1.10.2.jar nogui
        elif [ "$gui" ]
                then java -Xmx3896M -Xms1G -d64 -jar /home/minecraft/minecraft-server/minecraft_server.1.10.2.jar
        elif [ "$man" ]
                then echo "output: no nohup or and / gui: no output, and, gui / man: gives manpage similar output / none: silenced."
        else nohup java -Xmx3896M -Xms1G -d64 -jar /home/minecraft/minecraft-server/minecraft_server.1.10.2.jar nogui &
fi
Thanks in advance!
 
Old 07-18-2016, 10:32 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
You're passing in arguments, not environment variables. I recommend using a simple case statement with $1 (being the first argument e.g. "gui" in your example). See this init script example.

See also "man test" which will tell you more how to use the bracket for logic.

Last edited by sag47; 07-18-2016 at 10:34 AM.
 
Old 07-18-2016, 10:40 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
sag47 has his wizard hat on .... cause I read the script a few times and had no idea what was going on and was about to ask where all those variables were being set ... nice work

I would also suggest that writing the exact same piece of code bar a single piece of information 3 times could probably be improved.
 
Old 07-19-2016, 12:17 AM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Alternatively, man test states that:

[ STRING ] is equivalent to [ -n STRING ]

So you could change how you're calling the script. e.g.

Code:
# choose one of the following four ways

gui=1 minecraft_starter

output=1 minecraft_starter

man=1 minecraft_starter

minecraft_starter
So the script can be left as-is if you call it like the above four ways.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need shell-script help (very simple) oskar Linux - General 6 03-12-2008 07:08 AM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Simple Shell Script Help Kristijan Programming 3 06-13-2005 09:13 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration