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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
aix tls version 6 417
Image not there 4 56
Solaris 4.1.3 cloning and booting 13 83
Showing a username in UNIX and using that name in the script 4 49
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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

840 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