LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-27-2003, 08:47 PM   #1
WildChild978
LQ Newbie
 
Registered: Aug 2003
Location: Australia
Distribution: Mandrake 9.2
Posts: 12

Rep: Reputation: 0
Newbie to Shell Scripts


I grew up a MS DOS user and have "graduated" to linux.
I'm trying to create a shell script to run Jin, the java chess interface, which currently requires 'java -jar jin.jar' to run, and requires this command in the current directory.
I'm a lazy bum, so naturally I want to write a shell script that runs this, which I can then place a link to on my Desktop and click on when I want to run Jin.
I don't know where to start!
Is there a users guide to Shell Scripts someone can direct me to please?
Taaaaa,
WildChild
 
Old 11-27-2003, 09:08 PM   #2
Skyline
Senior Member
 
Registered: Jun 2003
Distribution: Debian/other
Posts: 2,104

Rep: Reputation: 45
Quote:
Is there a users guide to Shell Scripts someone can direct me to please?
A BASH shell scripting guide:

http://mirrors.sunsite.dk/ldp/HOWTO/...tro-HOWTO.html
 
Old 11-27-2003, 11:00 PM   #3
DurantDL
Member
 
Registered: Oct 2003
Location: Virginia, USA
Posts: 31

Rep: Reputation: 15
If you usually have a terminal open, make an alias:
% alias jin="java -jar jin.jar"
% jin

A simple bash script:
#!/bin/bash
java -jar jin.jar

Desktop shortcut depends on your window manager.
 
Old 11-27-2003, 11:02 PM   #4
WildChild978
LQ Newbie
 
Registered: Aug 2003
Location: Australia
Distribution: Mandrake 9.2
Posts: 12

Original Poster
Rep: Reputation: 0
Basic Guide

Thanks,
That looks ok.
Also, is there anything I need to watch out for when dealing with scripts and Directories with spaces in their names, ie. /home/wildchild/sub folder/

Cheers,
WildChild
 
Old 11-28-2003, 12:24 AM   #5
DurantDL
Member
 
Registered: Oct 2003
Location: Virginia, USA
Posts: 31

Rep: Reputation: 15
Path names with spaces must be quoted, or
they will be treated as two (or more) file names.

Three easy ways to quote: "file name", 'file name', file\ name

The "ls" command has an option to give you the last format.
Many programs also allow a "-print0" option to return "C" strings.
 
Old 11-28-2003, 02:55 AM   #6
BSlack
Member
 
Registered: Nov 2003
Location: Italy: 44° 42' N - 12° 11' E
Distribution: Slackware, what else?!!
Posts: 63

Rep: Reputation: 15
Quote:
Is there a users guide to Shell Scripts someone can direct me to please?
Bash Reference Manual

Advanced Bash-Scripting Guide

Have fun...
 
Old 11-28-2003, 04:44 PM   #7
WildChild978
LQ Newbie
 
Registered: Aug 2003
Location: Australia
Distribution: Mandrake 9.2
Posts: 12

Original Poster
Rep: Reputation: 0
Here's my script

#!/bin/bash
cd /home/wildchild/Program\ Files/jin-2.11b/
java -jar jin.jar

it seems I have to cd into the directory if I want to create a link to the script or it gives me the error "cannot find file 'Program'"
can anyone offer any improvement to this script, say for instance, to allow me to move the entire jin directory and still have the script work?
 
Old 12-02-2003, 10:11 PM   #8
DurantDL
Member
 
Registered: Oct 2003
Location: Virginia, USA
Posts: 31

Rep: Reputation: 15
Maybe tell java where to find the .jar file, like this:

java -classpath "/home/wildchild/Program Files/jin-2.11b" -jar jin.jar
 
Old 12-05-2003, 03:45 PM   #9
WildChild978
LQ Newbie
 
Registered: Aug 2003
Location: Australia
Distribution: Mandrake 9.2
Posts: 12

Original Poster
Rep: Reputation: 0
I don't see how that will help, as if I move my jin directory, the script will have the wrong path.
 
Old 12-06-2003, 11:12 AM   #10
DurantDL
Member
 
Registered: Oct 2003
Location: Virginia, USA
Posts: 31

Rep: Reputation: 15
You declare you want this shortcut to run from anywhere;
but you do not want to "cd", or include the actual path.
You can't selectively change one part of your configuration and not another;
you must set the CLASSPATH somewhere for java to know where to look:
1) in your local user environment, or
2) in the local/global shortcut, or
3) in the global Config.sys, or
4) in the global AutoExec.bat.
 
  


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
shell scripts newbie_m Linux - Newbie 3 01-18-2005 08:12 PM
shell scripts rocketgo Linux - General 10 12-01-2003 05:20 AM
Shell Scripts benwy Linux - Software 1 06-09-2003 02:58 AM
shell scripts nautilus_1987 Linux - General 3 08-30-2002 03:12 AM
Need Help with Shell Scripts!!!!!!!!!!! vicsharps Linux - Newbie 3 03-07-2002 09:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 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