# 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 %*


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,
###### Who is Participating?

Commented:
The syntax would be fairly similar.  tcsh is a little different from bash/sh shells and here is how you would do it in bash/sh

# contents of sample.sh
echo $1 cd$1

# shows the current directory
pwd

# displays all arguments 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 cmd.exe /c "mt.bat ...rest of command from your post..." # EOF sample.sh You will need to make sure that the shell script is executable. In unix you would issue the command: chmod +x sample.sh Good luck. 0 Author Commented: Can you please show me how to do it in tcsh? 0 Commented: #!/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. 0 Author Commented: @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 %*  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  0 Commented: 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? 0 Author Commented: 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. 0 Author Commented: 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. 0 Commented: 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$*
0

Commented:
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.
0

Author Commented:
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$*


Is that right?
0

Commented:
mt.bat is not something a unix/Linux command can run.

script.sh

#!/bin/sh

echo $1 cd$1
shift $* comman_you_want_need$*

You run the command
./script.sh directory parameter1 parameter2 parameter3
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.