simple shell - how to get a parameter typed in a shell script

Hi,
I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java [path to my program]myJavaprogram

I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe "myscript -myJavaprogram.
This is what I got so far

#!/bin/sh
# Print the current working directory.
java `pwd`
#end of runjava file

How do I read an argument that I would like to pass?
ie %runjava Test
And the command passed to the shell would be "java [directory]Test"

Thenk you

Inside a shell script you can read the arguments passed to your shell program by $1, $2, $3 .......
for e.g if your script file name is myscript and if you want to pass an argument to it like (myscript arg1) then inside myscript you can refer the arg1 by $1.

Hope this helps
:slight_smile:

As a follow-up question (that seems related):

I'm running .kshrc and want to script or alias the following:
ls -alF <i>regex</i> | more

I have not found how to pass an argument inside an alias
(e.g. alias dir='ls -alF $1 | more' does NOT work).

The following script 'dir' works:
#!/bin/ksh
ls -alF $1 | more

however, if I pass it an expression like '*.eva' it will only ls the first filename with the .eva extension (not ls all of the files with the .eva extension).

_Anyone_ who's read this far already has my sincere appreciation! If you can point me to man pages to help me solve this problem I'd appreciate it even more!

When you run your 'dir' script, such as:

dir *.eva

the shell expands this, same as if you had typed:

dir file1.eva file2.eva file3.eva

Your script processes only the first of these ($1). You could keep the shell from expanding it on the command line with:

dir "*.eva"

so that your script gets the unexpanded .eva as $1. Or you could change $1 in your dir script to $.

man ksh documents treatment of shell variables.

I am new to UNIX script can someone send me the sample script which accepts a parameter in the script and check for some condition as below

If $parm1 = "ABC"
do some process1
else
if $parm1 = 'DEF"
do some process2
fi
fi