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
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,
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,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
#!/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.
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.
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:
As an example, this command could be something like:
- 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
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?
A for loop from 2 to $# to build the list
Got to think thinks through.
Any particular reason to use tcsh rather than sh?
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.
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.
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 $*
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.
Using explicit paths, it should function no matter the shell environment.
ASKER
hmmm. You are right. I can just use bash/sh.
You the code will be like this?
Is that right?
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER