Writing Bash shell scripts corresponding to windows bat files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing Bash shell scripts corresponding to windows bat files
# 1  
Old 09-16-2010
Writing Bash shell scripts corresponding to windows bat files

Experts,

I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my code.

Code:
@ECHO OFF
IF NOT DEFINED MY_HOME goto home_not_set
IF DEFINED JAVA_HOME GOTO java_defined
ECHO Setting Java Home
set JAVA_HOME="%MY_HOME%\java\jre6_14"
SET PATH=%JAVA_HOME%\bin;%PATH%
:java_defined
set ACTIVEMQ_HOME=%MY_HOME%\message
GOTO end
:home_not_set
ECHO Set environment variable MY_HOME before running this script
GOTO end
:end
ENDLOCAL

where can i find a document or sample code to use in cygwin? i tried with #!/bin/bash. it started to print error at the end of file. do i need to set any path before writing scripts? please suggest or advise.

Thank you.

Last edited by Franklin52; 09-16-2010 at 09:01 AM.. Reason: Please use code tags!
# 2  
Old 09-16-2010
Here are the answers:

The code in shell:
Code:
# man test
if [ -z "${MY_HOME}" ]
then
	echo "Set environment variable MY_HOME before running this script".
	exit 1
fi

# man test
if [ -z "${JAVA_HOME}" ]
then
	export JAVA_HOME="${MY_HOME}\java\jre6_14"
	export PATH="${JAVA_HOME}\bin;${PATH}"
fi

export ACTIVEMQ_HOME="${MY_HOME}\message"

About the document, you can find something in CygWin's web site.

The error you are facing can be due to some CR's in the shell script file. Run the command dos2unix on it.

Code:
dos2unix <YourScript>

This User Gave Thanks to felipe.vinturin For This Post:
# 3  
Old 09-16-2010
@felipe.vinturin

Thank you very much for your reply friend. Thank you. Where can i find the corresponding shell script where i can learn the syntax in detail? It will be a great help as i have plenty files convert from .bat to .sh. Thank you in advance.
# 4  
Old 09-16-2010
A link I post another day in another post is this one: Unix shell scripting with ksh/bash

Also, if you have doubts you can post your questions, we have excelent people here!

Regards.
This User Gave Thanks to felipe.vinturin For This Post:
# 5  
Old 09-16-2010
Batch files don't remotely resemble script files. DOS/cmd doesn't even have real looping structures, just the "for" hack, ERRORLEVEL and/or gotos. Shell scripts have no gotos at all! ...but a forest of much more useful structures cmd never did. I think you'd be better off learning shell scripting instead of trying to "translate" your batch files.
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 09-16-2010
Quote:
Originally Posted by Corona688
Batch files don't remotely resemble script files. DOS/cmd doesn't even have real looping structures, just the "for" hack, ERRORLEVEL and/or gotos. Shell scripts have no gotos at all! ...but a forest of much more useful structures cmd never did. I think you'd be better off learning shell scripting instead of trying to "translate" your batch files.
I agree!

If you know what the scripts you will have to "translate" do, it is better rewrite them!

And post your questions here!
# 7  
Old 09-17-2010
@Corona688 @felipe.vinturin's

Thank you very much experts. @Corona688 would you please let me know where from i can learn shell scripting? Thank you

Best regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing Hbase and pig scripts in the bash script file

Hi, I have a script file where i'm validatig the input file and storing the validated records on HDFS. I wanted to load data from HDFS to HBASE using pig script. So for that i have created a HBASE table and written pig script to load data from HDFS to HBASE which is working fine. Now i wanted... (0 Replies)
Discussion started by: shree11
0 Replies

2. Shell Programming and Scripting

Writing hive scripts in bash script file

Hi, I wanted to load data from HDFS to HIVE by writing bash script. Description: I have written a bash script to validate the data and loaded validated data from local file system to HDFS. Now in the same bash script i wanted to load the data from HDFS to HIVE. How can i do it ? Also how tyhe... (2 Replies)
Discussion started by: shree11
2 Replies

3. Shell Programming and Scripting

Create Bash shell scripts corresponding to windows bat files

Experts, I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my... (1 Reply)
Discussion started by: rajuchacha007
1 Replies

4. Shell Programming and Scripting

writing shell scripts of commands

can anyone help me in writing a shell script to visualize how simple commands work and on what logic. For Eg: ls command how it lists out all the files and directories, need to write a simple script based on the commands source code.:D (0 Replies)
Discussion started by: rahul_11d
0 Replies

5. UNIX for Dummies Questions & Answers

Q about windows bat files

Hi, can you run a windows bat file or a VBscript from a shell script? #!/bin/sh PATH=/ $PATH/test.bat (1 Reply)
Discussion started by: cmac
1 Replies

6. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

7. Windows & DOS: Issues & Discussions

Urgent Need for Assistance: Triggering Windows bat files from UNIX

Hello, Is there a way to trigger a Windows bat file or program on a different machine from a different UNIX server using KSC file? I hope you can assist me with this. Thanks! (0 Replies)
Discussion started by: punyenye
0 Replies

8. Shell Programming and Scripting

Is writing shell scripts different than...

I am currently taking a linux shell scripting class and also a intro to programming class using QBASIC. Will this interfere with how i learn each one? Are they similar in some ways? I already took a unix course based on the commands and it was easy, but now i have to create programs. Also, how... (1 Reply)
Discussion started by: brentdeback
1 Replies

9. Shell Programming and Scripting

FTP Shell Scripts from Windows to Unix: files have exotic characters

Hey guys, I am working on my shell scripts in wordpad in windows. Then, I upload it to my unix using psftp, but when I open those files with "vi" in Unix, there are all these "^M" characters in the file. Would anyone of you have a clue as to why? Help would be appreciated. Thanks, Laud (4 Replies)
Discussion started by: Laud12345
4 Replies

10. UNIX for Dummies Questions & Answers

help for newbie writing shell scripts

Hi, I have just started a Systems Programming course and am required to write a c shell script as part of it. I have little to no clue about unix. The spec states that the script can be run only once on each host by a user, but the script can be run on different hosts by the one user. ... (2 Replies)
Discussion started by: richgi
2 Replies
Login or Register to Ask a Question