LinuxQuestions.org
Visit Jeremy's Blog.
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 01-05-2008, 07:37 AM   #1
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Rep: Reputation: 15
Question shell scripting/ bash/ a command with 3 parameters


hellow,

can anyone tell me how to tell make a script identify whether a command is written with three parameters?

thx alot in advance
maya
 
Old 01-05-2008, 07:49 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
By heart I thought the variable is $#. So you can check:

Code:
if [ $# -eq 3 ]
then
  echo three's a company
fi
To be sure check that $# variable in the Advanced Bash Scripting Guide. The link is in my signature.

jlinkels
 
Old 01-05-2008, 08:15 AM   #3
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
yes, thanks alot, i found it :
#Exceptions:
${#*} and ${#@} give the number of positional parameters.

but, i have another question about this program :
#!/bin/bash
# length.sh

E_NO_ARGS=65 --->what does this line mean?
if [ $# -eq 0 ] # Must have command-line args to demo script.
then
echo "Please invoke this script with one or more command-line arguments."
exit $E_NO_ARGS
fi
.
.
and how can i process a command entered by the user. because the rest of this program deals with defined variables !!.
.
var01=abcdEFGH28ij
echo "var01 = ${var01}"
echo "Length of var01 = ${#var01}"
# Now, let's try embedding a space.
var02="abcd EFGH28ij"
echo "var02 = ${var02}"
echo "Length of var02 = ${#var02}"

echo "Number of command-line arguments passed to script = ${#@}"
echo "Number of command-line arguments passed to script = ${#*}"

exit 0
 
Old 01-05-2008, 09:15 AM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,244

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Quote:
Originally Posted by mayaabboud View Post
E_NO_ARGS=65 --->what does this line mean?
if [ $# -eq 0 ] # Must have command-line args to demo script.
then
echo "Please invoke this script with one or more command-line arguments."
exit $E_NO_ARGS
fi
It means the variable E_NO_ARGS is assigned the value of 65. When the number of arguments is zero ([ $# -eq 0 ]) the program exits with this error number.

.
Quote:
Originally Posted by mayaabboud View Post
.
and how can i process a command entered by the user. because the rest of this program deals with defined variables !!.
{/quote]

$1 is the first argument, $2 the next, etc.
If you want to start programming Bash, please spend some hours and read the Bash Scripting guide. These are simple questions you ask, if you want to learn Bash programming thru asking question in this forum it is gonna take you a long time.

jlinkels
 
Old 01-05-2008, 11:22 AM   #5
mayaabboud
Member
 
Registered: Oct 2007
Posts: 53

Original Poster
Rep: Reputation: 15
i already read the shell-scripting guide on linuxcommand.org

but there are still pieces of info missing there

the scripting guide you pointed to is too short-explained !! i need a better one, and believe me it has been a week now that im trying to search through the internet for info, but im not finding the answer that i want,

so thats why im resorting to this website,
i thought i could get answers to concrete questions instead of having to spend one more week searching, for a simple thg !!!

maya
 
  


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
goto/label command for scripting in bash shell terry.trent Linux - Software 3 07-09-2010 11:15 AM
Help with Bash shell scripting HLM01 Linux - Newbie 7 01-31-2008 05:23 PM
BASH: run command with parameters from variable Roger Krowiak Programming 3 10-30-2007 04:27 AM
Bash shell scripting using if else nautz Linux - General 10 11-07-2006 10:47 AM
bash shell parameters jayeola Programming 4 05-15-2006 11:29 AM


All times are GMT -5. The time now is 05:24 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration