Batch to Shell Question??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Batch to Shell Question??
# 1  
Old 05-12-2012
Java Batch to Shell Issue: What's the correct equivalent of setlocal in Shell Script...

I know this is kindof a noob question, but Im trying to convert a simple batch file to shell, but Im new to shell scripting.

What would the following be in shell script:
Code:
setlocal
set OK=N

set CUR_DIR=%~dp0
set CURRENT_TIME=%TIME:~0, 1%%TIME:~1,1%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%

I've read up on setlocal and ~dp0 conversions to shell but I'm not sure... Also, Im not sure what set OK=N actually does.
But this is what I've come up with...

Code:
export LC_ALL=C
export OK=N

export CUR_DIR=$(dirname $0)
export CURRENT_TIME=$(date "+ %H%M%S")

Not Sure if its correct at all because Im not sure what setlocal and OK=N is actually doing on a windows machine vs mac/unix.
Also, couldn't figure out how to get the milliseconds in there like the batch file...

Any help would be appreciated...
Thanks

Last edited by scrumx; 05-12-2012 at 03:25 PM.. Reason: update title
# 2  
Old 05-13-2012
Why does the script need time to miliseconds? I suspect it's attempting to generate a unique temporary file, in which case the unix mktemp command is preferable.

If you really need time with ms and you have gnudate you can do:

Code:
CURRENT_TIME=$(date "+%H%M%S")$(( $(date +%N) / 10000000 ))

MSDOS setlocal has nothing to do with locale, it controls the scope of environment changes not language stuff.

Last edited by Chubler_XL; 05-13-2012 at 09:34 PM..
# 3  
Old 05-13-2012
Thanks Chubler,

So basically to give you and everyone a little background on the entire script is that it is a setup script that downloads and unzips things like eclipse, maven, apache, tomcat, etc... and places them in their correct directories so that when the script runs once; the development environment is setup for any new user...

That said your response makes sense and is very appreciated...

I also figured out what the OK=N is with the help of a question I posted in stackOverflow, basically in the batch script it was a variable that was created for debugging purposes only...

Thanks again for your help...

Last edited by scrumx; 05-13-2012 at 11:48 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Converting the following batch script to Linux shell

I am currently migrating to ubuntu from my windows system. Now I am learing to convert all my batch scripts into linux shell. Although the common commands are more or less similar, but I found it difficult for the following set of commands in windows cmd: setlocal :PROMPT SET /P... (2 Replies)
Discussion started by: net.genere
2 Replies

2. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

3. Shell Programming and Scripting

Shell script from batch file

Hi, I am a junior dba and started carrier very new. I have a batch file to create some script of db creation. I want that batch file to convert in .sh file so that I can directly run that in the AIX box to generate those files. Please help me with the code for AIX. Batch file is here: ... (2 Replies)
Discussion started by: dba_aix
2 Replies

4. Shell Programming and Scripting

Need to run the batch script from shell scripting

Hi All, I am working on shell scripting.My script is completed but I have one task that is to trigger the batch script(with or without parameter) from my shell scripting(reside on linux system) and output which is geneareted by the batch should e.g. if batch script creates any files then I want... (5 Replies)
Discussion started by: anuragpgtgerman
5 Replies

5. Shell Programming and Scripting

Conversion batch shell script

while converting batch file to shell script ...dis command is ther i dunno how to change...can anyone knws how to change into shell script rm !(D:\temp\XX.txt) (3 Replies)
Discussion started by: monisha
3 Replies

6. Shell Programming and Scripting

Executing a batch of files within a shell script with option to refire the individual files in batch

Hello everyone. I am new to shell scripting and i am required to create a shell script, the purpose of which i will explain below. I am on a solaris server btw. Before delving into the requirements, i will give youse an overview of what is currently in place and its purpose. ... (2 Replies)
Discussion started by: goddevil
2 Replies

7. UNIX for Dummies Questions & Answers

Unix shell, Dos batch

Is the unix shell script equivalent to dos batch command? Thanks (2 Replies)
Discussion started by: zhshqzyc
2 Replies

8. Shell Programming and Scripting

Help with 'batch conversion using lame' shell script

Hi. I am trying to write an sh script that will: 1. take each wav file in ~/Documents 2. convert each into mp3 format using "lame" encoder 3. save the new mp3 in ~/Documents/newmp3s. It has to follow the 3 steps in this order for each wav file before taking the next file. I tried a... (8 Replies)
Discussion started by: Kingzy
8 Replies

9. UNIX for Advanced & Expert Users

Batch file question

EDIT: Is this wrong thread? Hi I am on an Apple Mac and I am trying to run this batch file on my Mac and was wondering if anyone could tell me what a script that will make this run and work on my Mac. I was hoping that you could tell me the script in the shell format? So here's the batch... (4 Replies)
Discussion started by: Billy5555100
4 Replies

10. UNIX for Dummies Questions & Answers

batch command in a shell script

How do I execute a batch command from a script, which "waits" with the next command until the first one has finished? ======= A piece of my script looks like this: #!/bin/sh (...) # run a long batch job: ./run_calculation.sh # then rename resulting file: mv output.dat backup.dat (...) ... (7 Replies)
Discussion started by: ivvo
7 Replies
Login or Register to Ask a Question