LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 08:48 AM   #1
frizzant
LQ Newbie
 
Registered: Jul 2016
Posts: 1

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, 11:32 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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 11:34 AM.
 
Old 07-18-2016, 11:40 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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, 01:17 AM   #4
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,831
Blog Entries: 36

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 08:08 AM
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 06:34 PM
Simple Shell Script Help Kristijan Programming 3 06-13-2005 10:13 PM
simple shell script Greg_courageous Programming 2 05-12-2004 05:34 PM
Simple C Shell script is not so simple elconde Programming 2 09-17-2001 12:53 AM


All times are GMT -5. The time now is 04:38 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration