BAT to SH help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BAT to SH help
# 1  
Old 05-10-2012
BAT to SH help

First off, let me apologize if I'm posting this in the wrong place!

I am a newbie to this forum, to shell scripting and to Linux so please bare with me.

I created a script on the windows environment that makes a call to a java application and extracts a return value from the java app. It works in windows but after moving the script to Linux and converting it to Linux (dos2unix) to remove unwanted characters, I am getting syntax errors. here's the line code failing:

Code:
for /f "delims=" %%A in ('java PDFGenerator %*') do set args=%%A

basically it calls the java app and sets whatever arguments are returned to %%A. I know that shell scripting uses $ instead of % but I cannot re-write this code in Linux. I've been breaking my head trying to get it to work but basically I need all the help i can get!

THANK YOU SO MUCH IN ADVANCE!
# 2  
Old 05-10-2012
Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!", "Doubt" or anything that does not accurately reflect the nature of your problem. Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

The UNIX and Linux Forums
# 3  
Old 05-10-2012
Windows CMD is nothing like UNIX sh. Windows makes do with its lack of proper looping structures and quoting by making 'for' do 99 different ad-hoc things. UNIX sh has its own 'for' nothing like Windows', proper while loops, proper do loops, and other such structures to do all the same jobs in a more comprehensible way. The closest it has to goto, is case. So, you cannot "port" this kind of code to UNIX. You just have to rewrite it.

Fortunately, that shouldn't be hard, once you tell us what the above is actually supposed to do.

Could you explain exactly what the above code is supposed to do? Run 'java pdfgenerator file1', 'java pdfgenerator file1', etc, and catch all their results? or what?

Last edited by Corona688; 05-10-2012 at 04:53 PM..
# 4  
Old 05-10-2012
What Operating System and version are you running and which Shell are you using?
Please post the whole original Batch File and the output from the MSDOS set command from the environment where the Batch File runs (blotting anything confidential with X's).
Have you installed Java on the Linux computer?
# 5  
Old 05-11-2012
As the others said we may need the full script to determine what you are trying to do. I believe the posted line runs java PDFGenerator and captures the last line of output in the variable args.

Under unix you would do something like this:
Code:
args=$(java PDFGenerator $@ | tail -1)

This User Gave Thanks to Chubler_XL For This Post:
# 6  
Old 05-11-2012
Subject seemed clear enough. BAT to SH.

It looks like
Code:
for i in $A
do
java PDFGenerator $i
done

The delim= probably sets the delimiter for the command line.
In a batch file, the % gets escaped with a second % - why I don't know.

Last edited by Scrutinizer; 05-11-2012 at 03:25 AM.. Reason: Clarity; mod: code tags instead of quote tags
# 7  
Old 05-11-2012
Corona688 I apologize for the subject text.

Basically I have a python script that calls this .sh script and passes arguments to it. These arguments show as %* after the PDFGenerator call. The .sh script has 2 lines of code only what it does in this line is, it calls the PDFGenerator java app passing the arguments that came from my python script to it. The java app returns some arguments that are set into the "args" variable. Then the 2nd line of code (which has already been tested with hardcoded values and works) calls another python script passing the "args" value to it.

here's my second line:
python PDFGenerator.py PDFGenerator 'hello world' <--- this would be my "args" variable.

What Chubler_XL posted does exactly what i want. Thank you Chubler_XL! And thank you all who replied!

Last edited by arod291; 05-11-2012 at 12:42 PM.. Reason: Got my answer from a post!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Convert .sh to .bat please

Can someone translate this code to .bat for me? I have no clue. #!/bin/sh WAS_HOME="/opt/websphere/appserver/profiles/AppSrv01" WAS_APP_SERVER="server1" WAS_PROFILE_NAME="AppSrv01" echo "Stopping App Server" "${WAS_HOME}/bin/stopServer.sh" -profileName $WAS_PROFILE_NAME $WAS_APP_SERVER... (1 Reply)
Discussion started by: Blogger11
1 Replies

2. Shell Programming and Scripting

Need help with bat file!!!

I need to put/get files from Windows machine to Unix machine and vice-versa. I wrote a text file "ftp1.txt" as below. naga naga06 cd /root/Naga prom off get time.unl bye I wrote another bat file "ftp.bat" as below. ftp -n -s:C:\Users\Naga\Desktop\ftp1.txt IP_ADDRESS but... (2 Replies)
Discussion started by: Naga06
2 Replies

3. Shell Programming and Scripting

bat to shell

I have serverfiles of same game. and there are bat files. I wont to run this on debian. The files are difficult, eg :######################################################################## :# File name: server_start.bat :# Edited Last By: Mike Gleaves (ric) :# V 1.0 1-10-2008 :# Comment:... (5 Replies)
Discussion started by: Qentinios
5 Replies

4. Windows & DOS: Issues & Discussions

Executing .bat file

Hi , I have a bat file on windows machine ,I need to excute it from my local unix machine using sambe utility.Is there any comman to execute the .bat file remotely. Using samba utility i can post files to and fro from windows to unix but i don't comman to exute the .bat file. can any one... (2 Replies)
Discussion started by: Raamc
2 Replies

5. Windows & DOS: Issues & Discussions

.bat script help

hi I need to rediret an content of one file and append it to another file. I need it in .bat script. I tried this, first.txt I love to write script type first.txt >> out.txt type first.txt >> out.txt out.txt I love to write scriptI love to write script you see the... (6 Replies)
Discussion started by: ilugopal
6 Replies

6. Shell Programming and Scripting

.bat or .pl script help

hi I need to rediret an content of one file and append it to another file. I need it in .bat script. I tried this, first.txt I love to write script type first.txt >> out.txt type first.txt >> out.txt out.txt I love to write scriptI love to write script you see the second... (1 Reply)
Discussion started by: ilugopal
1 Replies

7. Shell Programming and Scripting

Simple bat file

Hi guys, I need a *.bat to run a ksh file in the shell on Windows NT...nothing more :) How do I do it? I tried with the following but it failed: set INFORMIXDIR=D:\user-applications\informix set PATH=%INFORMIXDIR%;%PATH% D:\user-applications\MKS\mksnt\sh.exe C:\hk_9.2\C3_weekly_auto.ksh... (4 Replies)
Discussion started by: Dird
4 Replies

8. Shell Programming and Scripting

how to call a .bat file using KSH

Hi all, I am a very new user for korn scripting and in a process of learning. i have a .bat file that calls a .vbs file which calls a macro used to convert an excel spread sheet to .csv file... Now i want to automate this process. I want to call this bat file using a korn script or a korn... (16 Replies)
Discussion started by: bhagya2340
16 Replies

9. Windows & DOS: Issues & Discussions

one question for .bat file

Hi! I'm very sorry for such simple and silly question but I cannot answer it by myself. Can you please help me? In .bat file I should run the C program which is in other directory, and the input configuration file is in this directory too. This dir name is in dirRun variable. The... (3 Replies)
Discussion started by: Anta
3 Replies

10. 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
Login or Register to Ask a Question