Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert DOS Batch file into Shell script

Posted on 2011-03-21
3
Medium Priority
?
821 Views
Last Modified: 2012-06-27
Hi, I have a Dos Batch file and I want to convert it into Linux script because I may run the batch file in the different enviroment. Please ignore the -- or -, it is the option of the commerical software PLINK.

set PLINK=\\Sun\GroupData\APP\plink\plink.exe
set src=\\Sun\GroupData\ABC\Englind\Impute
set pheno_path=\\Sun\GroupData\ABC\XYZ\plink_input
set pheno=%1
set chr=%2

if not exist %pheno%\nul mkdir %pheno%
%PLINK% --bfile %src%\bed\chr%chr% ^
 --pheno-name logh ^
 --assoc ^
 --qt-means --out %pheno%\chr%chr%

Open in new window


Thanks
0
Comment
Question by:zhshqzyc
  • 2
3 Comments
 
LVL 3

Assisted Solution

by:gopisera
gopisera earned 248 total points
ID: 35185916
Instead of set operator in windows scripting  in linux  use export

e.g.,
export  src=\\Sun\GroupData\ABC\Englind\Impute

and you can wirte the if condition similar to below

if [ -nf  /x/x ]; then
echo "Hai"
els
echo "Hello"
fi

if the file /x/x exists display Hello else Hai.

You have to convert manually, line by line from windows to Korn shell scripting
 
0
 
LVL 20

Accepted Solution

by:
simon3270 earned 252 total points
ID: 35187985
I assume that there is a UNIX/Linux equivalent of the "plink.exe" command, presumably called "plink".  It woudl be easiest to mount \\Sun\Groupdata onto a local directory before you start (as the root user):
mkdir /mnt/groupdata
mount //Sun/GroupData /mnt/groupdata

Open in new window

Then the script would be as follows, with the same 2 parameters as the DOS one:
PLINK=/mnt/groupadta/APP/plink/plink
src=/mnt/groupdata/ABC/Englind/Impute
pheno_path=/mnt/groupdata/ABC/XYZ/plink_input
pheno=$1
chr=$2

if [ -d $pheno ]; then
  mkdir $pheno
fi
$PLINK --bfile $src/bed/chr${chr} \
 --pheno-name logh \
 --assoc \
 --qt-means --out $pheno/chr${chr}

Open in new window

0
 
LVL 20

Expert Comment

by:simon3270
ID: 35191051
Why do you always see errors *after* posting?  :-(

The if test should be "if [ ! -d $pheno ]" (missed !)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question