Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
944 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 500 total points
ID: 24038608
edit the .bat file and change it to

java TEST $1 $2
0
 
LVL 62

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

972 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