Help with batch file
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 - 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 your for your comment! |
There are a lot of scripting languages usable with Linux, but by far the most common is BASH.
"man bash" will tell you everything about BASH syntax - but is a bit terse and hard to read for newcomers. Go to this page and you'll find everything you need. I suggest you begin with "Introduction to Linux - A Hands on Guide" and/or "Bash Guide for Beginners". Then the "Advanced Bash-Scripting Guide" will tell you a lot more. |
Something like (not tested and I'm not fluent in .bat programming)
Code:
#!/bin/bash
|
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.) |
Hi,
Did you make your script executable? And how do you start it? Just by typing the name? To make executable: Code:
chmod +x <yourscriptname> Code:
sh <yourscriptname> Code:
./<yourscriptname Kind regards, Eric |
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 :( |
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 Code:
: not found |
Quote:
|
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: Code:
"$_JAVACMD" -Xmx256m -jar "$_FELIXJAR" "$1" "$2" "$3" "$4" |
To check you could insert these commands in your script before the quoted one:
Code:
echo '"$_JAVACMD" -Xmx256m -jar "$_FELIXJAR" "$1" "$2" "$3" "$4"' |
Quote:
Code:
"$_JAVACMD" -Xmx256m -jar "$_FELIXJAR" "$@" |
To see exactly what bash is doing (debug mode) use this line
set -xv as the 2nd line ie directly after the #!/bin/bash |
Thanks a lot, everyone! Really great help here!! :)
(Empty Parameters) I solved the problem by filtering out empty parameters on program level. You never know .. |
Quote:
The Thread Tools menu can be used to mark threads SOLVED. |
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.
|
All times are GMT -5. The time now is 11:18 PM. |