?
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
?
940 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

743 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