Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello
I wonder if anybody could help me out in a quick translation of a Windows batch file for the Linux environment. It is quite simple, so I guess I wouldn't need to learn all about bash or whatever.
The Windows script is (excerpt) as follows:
Code:
@echo off
setlocal
set _PORTROOT=NeuInstall\Felix
set _JAVACMD=java.exe
if exist "%_PORTROOT%\jre\bin\java.exe" set _JAVACMD="%_PORTROOT%\jre\bin\java.exe"
set _FELIXJAR="%_PORTROOT%\felix.jar"
if exist %_FELIXJAR% goto startjar
set _FELIXJAR="%_PORTROOT%\felix-2.jar"
if exist %_FELIXJAR% goto startjar
goto ende
:startjar
%_JAVACMD% -Xmx256m -jar %_FELIXJAR% %1 %2 %3 %4
goto ende
:ende
endlocal
So basically what I need to know is
- setting local variables
- dereferencing local variables
- test for file or dir existence
- passing command parameters
- if-then-else construct
It is important than "_PORTROOT" contains a relative path name (as opposed to an absolute path name).
What scripting language is to be used? In other words: what scripting language am I into normally on a Linux console prompt?
Thank you very much for the answers!
I try to work it out ..
After creating a script file I cannot run it from the console. Could you give me a hint as to how to start such a script. When typing its name I get reply "no such command ..." or similar.
Starting it from Nautilus creates a flash of terminal but immediately disappears again. Looks like a script problem, but how to assess it? (I'ld need the console window to stay open.)
To run the scripts you need, either to make it executable, or to launch bash and give the script name as an argument.
So do this:
chmod +x <script name>
then go to the directory where the script live (cd /full/path/to/directory) and type:
./</script name>
or:
/full/path/to/directory/<script name>
alternatively you could type:
bash <script name>
provided you are in the directory where teh script live, or:
bash /full/path/to/directory/<script name>
EDIT Just late, again
Last edited by Didier Spaier; 05-03-2010 at 03:37 AM.
Hi again
I'm a bit at a loss because I can't find the error.
Currently I am testing the following work-out:
Code:
#!/bin/bash
_PORTROOT=NeuInstall/FELIX-Java
_JAVACMD=java
if [ -f "$_PORTROOT/ljre/bin/java" ]; then
_JAVACMD=./$_PORTROOT/ljre/bin/java
fi
echo JAVACMD = $_JAVACMD
_FELIXJAR="$_PORTROOT/FELIX.jar"
if [ ! -f "$_FELIXJAR" ]; then
_FELIXJAR="$_PORTROOT/FELIX-s.jar"
fi
echo FELIXJAR = $_FELIXJAR
$_JAVACMD -Xmx256m -jar $_FELIXJAR #"$1" "$2" "$3" "$4"
I've started it with "sh felix" (where 'felix' is the batch file) and receive the following reply at the prompt. I've tried some variants but it is always the same.
Code:
: not found
felix: 20: Syntax error: end of file unexpected (expecting "then")
Hi again
I'm a bit at a loss because I can't find the error.
Currently I am testing the following work-out:
Code:
#!/bin/bash
_PORTROOT=NeuInstall/FELIX-Java
_JAVACMD=java
if [ -f "$_PORTROOT/ljre/bin/java" ]; then
_JAVACMD=./$_PORTROOT/ljre/bin/java
fi
echo JAVACMD = $_JAVACMD
_FELIXJAR="$_PORTROOT/FELIX.jar"
if [ ! -f "$_FELIXJAR" ]; then
_FELIXJAR="$_PORTROOT/FELIX-s.jar"
fi
echo FELIXJAR = $_FELIXJAR
$_JAVACMD -Xmx256m -jar $_FELIXJAR #"$1" "$2" "$3" "$4"
I've started it with "sh felix" (where 'felix' is the batch file) and receive the following reply at the prompt. I've tried some variants but it is always the same.
Code:
: not found
felix: 20: Syntax error: end of file unexpected (expecting "then")
Works for me, copy-and-pasted from your post. Are you creating the file in a Windows editor? If so then yo need to convert its line ends by processing it with the fromdos command.
Ah, that was the problem! I edited the file in geEdit, but with a source coming from Windows. Obviously the crlf have been preserved all the time. With a few additions, the script is running fine now.
One problem remains. This is my current start command in the script:
Expressions '"$1"' etc. are meant to transfer commandline parameters from the batch over to the java program. I wonder if this is correctly done because I receive an unexpected parameter when leaving these values void. Strange as it might seem, this parameter is the device denotation of where program and batch reside ("/media/USBDISKPRO"). Is that possible? (Might as well be a program bug.)
Expressions '"$1"' etc. are meant to transfer commandline parameters from the batch over to the java program. I wonder if this is correctly done because I receive an unexpected parameter when leaving these values void.
My mistake -- I assumed they would always be present; when they are not an undesirable effect of the double quotes is to create empty strings as arguments. Try
If you allow me another question: Is it common to use certain file extentions for bash script files? I see advantage in using some to avoid possible naming conflicts with directories e.g.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.