LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Newbie to Shell Scripts (https://www.linuxquestions.org/questions/programming-9/newbie-to-shell-scripts-120601/)

WildChild978 11-27-2003 08:47 PM

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

Skyline 11-27-2003 09:08 PM

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

DurantDL 11-27-2003 11:00 PM

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.

WildChild978 11-27-2003 11:02 PM

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

DurantDL 11-28-2003 12:24 AM

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.

BSlack 11-28-2003 02:55 AM

Quote:

Is there a users guide to Shell Scripts someone can direct me to please?
Bash Reference Manual

Advanced Bash-Scripting Guide

Have fun...

WildChild978 11-28-2003 04:44 PM

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?

DurantDL 12-02-2003 10:11 PM

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

java -classpath "/home/wildchild/Program Files/jin-2.11b" -jar jin.jar

WildChild978 12-05-2003 03:45 PM

I don't see how that will help, as if I move my jin directory, the script will have the wrong path.

DurantDL 12-06-2003 11:12 AM

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.


All times are GMT -5. The time now is 06:28 AM.