This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing command line argument in shell script

 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
just wondering how could i define a variable in a shell script and pass an argument to it from command line. specifically, i would like to do something like the following:
Script
------------------
myScript(script name)
var
This a var argument passed in command line.
now in command line, typing following
myScript Testing
should display:
This is Testing argument passed in command line.
hope, i have been clear what i would like to do.
appreciate your help.
thanks.
himal
 
Blaine Mincey
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick example....
Command line
$ HelloWorld Blaine
#/bin/bash
VAR_NAME=$1
echo "Hello, $VAR_NAME"
Should result in
$ Hello, Blaine
Remember to make your shell script executable...
Blaine
blaine_mincey@mindspring.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic