Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


what is the command To print script arguments

Answers were Sorted based on User's Feedback



what is the command To print script arguments..

Answer / shabab

$* and $@ are the right answers

$# - prints out the number of arguments passed

Consider the below code
########################
for i in "$*"
do
print $i
done

for i in "$@"
do
print $i
done
########################

and you call the script by saying

#samp.sh hai welcome to "Unix Forum"
hai welcome to Unix Forum
hai
welcome
to
Unix Forum


The first line is the output by printing out $*
the next four lines are with the help of $@.

So
$* will combine all arguments to a single string
$@ will have each arguments as a seperate string

Is This Answer Correct ?    4 Yes 0 No

what is the command To print script arguments..

Answer / bc

$@ seems to be another option. Difference between $* and $@
is that $@ recognizes multiple strings given in quotes as a
single word.

Is This Answer Correct ?    3 Yes 0 No

what is the command To print script arguments..

Answer / guest

echo $* or $#

Is This Answer Correct ?    2 Yes 1 No

what is the command To print script arguments..

Answer / alf55

There is a difference between using $@ and using "$@". The
first is the same as using $*, while the latter is what was
being described ad $@. It only handles the arguments
correctly when used as "$@". However, you will not see where
the arguments are changing in its simple usage in a print.

echo "arguments are:"; for arg in "$@"; do echo "
${arg}"; done

Will show each argument on a new line indented by four spaces.

Here is an example:
[code]
bash$ function show_simple_args
> {
> echo "There are $# arguments passed, can you find
them correctly?"
> echo "using \$*:"
> echo $*
> echo "using \$@:"
> echo $@
> echo "using \"\$@\":"
> echo "$@"
> echo "using for loop with \$*:"
> echo "arguments are:"; for arg in $*; do echo "
${arg}"; done
> echo "using for loop with \$@:"
> echo "arguments are:"; for arg in $@; do echo "
${arg}"; done
> echo "using for loop with \"\$@\":"
> echo "arguments are:"; for arg in "$@"; do echo "
${arg}"; done
> }
bash$
bash$ show_simple_args "arg 1" "arg 2" "arg 3" "arg 4"
There are 4 arguments passed, can you find them correctly?
using $*:
arg 1 arg 2 arg 3 arg 4
using $@:
arg 1 arg 2 arg 3 arg 4
using "$@":
arg 1 arg 2 arg 3 arg 4
using for loop with $*:
arguments are:
arg
1
arg
2
arg
3
arg
4
using for loop with $@:
arguments are:
arg
1
arg
2
arg
3
arg
4
using for loop with "$@":
arguments are:
arg 1
arg 2
arg 3
arg 4
bash$
[/code]

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Linux Commands Interview Questions

What will happen when a system call is encountered in a user program?

0 Answers   Google,


What does uname command do?

0 Answers  


1). What are the situation in process is duplicate is linux box.? 2) Give me 5 situation to kill a process?

1 Answers   Perot Systems,


How to shuffle the GRUB booting from one Disk to other?

1 Answers  


what is the command To print script arguments

4 Answers   Google,


What is finger in networking?

0 Answers  


why is the tar command used?

0 Answers  


How do you find out the server processes running?

4 Answers   HP,


what is the booting process of linux systen and explain it,is the first process comes under the installation process.

3 Answers   CSC, EA Electronic Arts, Mind Tree, vsworx,


Is llvm a virtual machine?

0 Answers  


What is tty in linux command?

0 Answers  


What can you tell about the tar command?

0 Answers  


Categories