Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to write tcsh that does the same stuff as batch file?

I have the following batch file that I call from a Java code. The following batch file (mtCheckGui.bat) is for the Windows OS:

mtCheckGui.bat
ECHO %1
cd %1
ECHO %*
mt.bat -using A @perl //some/path/in/here/mtcheck -gui -createXML -quiet %*

Open in new window


I would like to write a shell script in tcsh to do do same stuff that I do in the file batch do that I will be able to call it from the same code in a Unix OS.

So, how can I write this batch file commands in a tcsh?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of Bill Riedy
Bill Riedy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

Can you please show me how to do it in tcsh?
Avatar of arnold
#!/usr/bin/tcsh

echo $1
cd "$1"

What arguments do you pass to your batch script?

Bill1965 took the time to answer your question and provide you an explanation of their use/meaning.
Avatar of Tolgar

ASKER

@arnold: The first argument that I pass is a directory. The others are:

- file with its full path
- and some arguments such as
    -gkl something1 -gkl something2


Eventually, I want the tcsh to cd to the first argument and then run this command with the rest of the arguments:

mt.bat -using A @perl \some\path\in\here\mtcheck -gui -createXML -quiet %*

Open in new window


As an example, this command could be something like:

mt.bat -using A @perl \some\path\in\here\mtcheck -gui -createXML -quiet -f some\file\with\its\path.c -gkl something1 -gkl something2 -gkl something3

Open in new window

If memory serves me right, $# will return the number of elements.

A for loop from 2 to $# to build the list


Got to think thinks through.
Any particular reason to use tcsh rather than sh?
Avatar of Tolgar

ASKER

The default shell is tcsh in the company. And the environments are set correctly for tcsh but it is not guaranteed for bash/sh. Therefore, I am worried that mt.bat will not on tcsh path and the code will not work. That's why want to use tcsh.
Avatar of Tolgar

ASKER

On the other hand, I think the solution proposed  by bill1965 is not right.

Because after I use the first argument to cd to the directory. I want to get rid of it and I want to use the rest of the arguments in the last command.
Using the argument does not shift it out.
I.e.
Your arguments are
Directory file1 file2 file3
$1 directory
$2 file1
$3 file2
$4 file3

$* will return all no matter whether you referenced one or more earlier.

You can try shift $* after cd $1

echo $1
cd $1
shift $*
echo $*
On the shell what environment are you looking for?  What does mt.bat supposed to be.

Using explicit paths, it should function no matter the shell environment.
Avatar of Tolgar

ASKER

hmmm. You are right. I can just use bash/sh.


You the code will be like this?
echo $1
cd $1

# shows the current directory
pwd

# displays all arguments passed to the sh program
echo $*

shift $*

#displays all arguments except the first one passed to the sh program
echo $*

# .bat files are not run directly they are interpreted and run 
# by the command processor in Windows which will be cmd.exe
mt.bat -using A @perl //some/path/in/here/mtcheck -gui -createXML -quiet $*

Open in new window


Is that right?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial