Solved

How do I pass AIX Unix Environment Variables as parameters from the command line to inside a .bat file?

Posted on 2009-03-31
4
930 Views
Last Modified: 2013-12-20
Let's say I have a .bat file to run in Unix-AIX and it's named TEST.bat...

TEST.bat runs a Java program that accepts two parameters, so it's contents are something like this:

      java TEST <param1> <param2>
      
So to run this file, I just type "TEST.bat" on the command-line, right?
      
However, I want to remove the parameters from the .bat file and enter them on the command-line instead, as such:

      > TEST.bat <param1> <param2>
      
What should be the contents of the .bat file now that the parameters are supplied outside it? How do you pass it into the .bat file so it can be used by the Java files as parameters in exactly the same way as the initial setup?
0
Comment
Question by:StephenSpeaks
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24036632
Hi,
positional parameters for shell scripts take the form $1, $2, ... $n
So, if your procedure TEST.bat contained e.g.

#!/bin/sh
echo $1 $2
exit
and you call it by "TEST.bat Hello World" the result will be
Hello World
There are some special variables in this context, e.g.

$# - number of arguments given (example above: 2)
$? - exit status of last command
$@ - all arguments given (example above: "$@" -> "Hello World")  
Invoking - either have the first line of the script as I wrote above ("!/bin/sh") to tell which shell to use for execution, or call it by "sh TEST.bat"
In the first case, the script must be made "executable" by issuing "chmod +x TEST.bat"

btw. you don't need a file suffix for Unix.
HTH
Cheers
wmp
 
 
 
 
 
0
 
LVL 14

Expert Comment

by:sjm_ee
ID: 24036656
The other, less common way to influence a child process is via environment variables. These can either be set "from now on" by setting the value of an exported variable, or "for this command" by setting them on the command line.

An example of "from now on" would be:

TERM=vt100
export TERM
vi

In this case, "vi" will behave as if it is running on a vt100 terminal. This kind of incantation is useful if you will be running many commands which are all influenced by the same values, to save typing the value on each command line.

An example of "for this command" would be:

TERM=vt100 vi

This will run the vi command with the value of "TERM" set to "vt100" just this once, and not for the future.
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 125 total points
ID: 24038608
edit the .bat file and change it to

java TEST $1 $2
0
 
LVL 61

Expert Comment

by:gheist
ID: 24039267
Lets say .bat file will not run on AIX...
You have to write shell scripts, perl scripts etc...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now