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
929 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…
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.

744 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

16 Experts available now in Live!

Get 1:1 Help Now