The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-07-2001
Registered User
 

Join Date: Nov 2001
Location: UK
Posts: 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
Reply With Quote
Forum Sponsor
  #2  
Old 11-07-2001
Registered User
 

Join Date: Nov 2000
Location: India
Posts: 83
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
Reply With Quote
  #3  
Old 12-04-2001
Registered User
 

Join Date: Dec 2001
Location: Portland, OR
Posts: 1
Question regular expressions and command-line arguments

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!
Reply With Quote
  #4  
Old 12-05-2001
Jimbo
Guest
 

Posts: n/a
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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0