![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing parameter 4m shell script to a DB stored procedure | hema2026 | Shell Programming and Scripting | 0 | 11-16-2007 03:55 AM |
| How to pass a parameter from one Shell-script to another Shell-script | subodhbansal | Shell Programming and Scripting | 2 | 09-22-2007 02:19 AM |
| passing parameter from Shell-script to Sql-script | subodhbansal | Shell Programming and Scripting | 0 | 09-21-2007 03:15 AM |
| Shell script with input parameter | jhmr7 | UNIX for Dummies Questions & Answers | 1 | 07-12-2005 09:04 PM |
| parameter file for a shell script | bryan | Shell Programming and Scripting | 2 | 02-25-2005 09:58 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Hi
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 |
|
#3
|
|||
|
|||
|
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! |
|
#4
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|