LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-26-2011, 04:57 PM   #1
evillan
LQ Newbie
 
Registered: Feb 2011
Posts: 1

Rep: Reputation: 0
Bash scripting: Arguments to script


I'm a noob a bash scripting and want to write a script where the number of arguments (i.e. $ script.sh arg1 arg2 arg 3... etc.) varies.

Is there any easy way to do this?

The arguments will later be used in the script and should have individual names (but that shouldn't be a problem, i.e. @1, @2, @3 etc.).

Furthermore is there a simple way to count the number of arguments? I could of course make a for loop or something, but it would be great if there was an actual function.

Thank you!
 
Old 02-26-2011, 06:57 PM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
look at $#, $*, shift etc.

You should READ THE MANUAL.
 
Old 02-27-2011, 03:54 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,516

Rep: Reputation: 240Reputation: 240Reputation: 240
or for

why don't people RTFM?

That's how to learn.
 
Old 02-27-2011, 04:00 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,417
Blog Entries: 55

Rep: Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627
Give the man a fish.

Code:
function help() { echo "Heres some Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html 
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html 
http://www.tldp.org/LDP/abs/html/"; }
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How are arguments passed to a bash script? jiml8 Programming 1 04-09-2009 05:28 PM
bash script arguments R3N3G4D3 Programming 5 11-01-2007 10:16 AM
can awk see bash script arguments ? sharapchi Programming 7 12-14-2006 08:03 PM
[bash-scripting]functions + arguments hylke Programming 14 10-05-2004 01:48 AM
bash scripting - referring to external arguments into loops linsson Linux - General 2 07-23-2004 12:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration