Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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 is grep command in linux with examples?

0 Answers  


What are vim commands?

0 Answers  


What does ls mean in linux?

0 Answers  


What is a makefile in c?

0 Answers  


How do I find the linux version?

0 Answers  






The ‘logout’ built in command is used to

0 Answers  


I have my default runlevel is init5 now i have configured to init 3,now i wanna run my system in init3 process without reboot the system .How will you do for this scenario?

6 Answers   Span Systems,


what is the command to check network interfaces in our system? how to set etho to 10 full duplex speed?

2 Answers  


In a company there are 3 groups i.e Finance, HR and Marketing. Each groups having 3 members. There is a file named as file1.txt. The permission set for the above file is rwx-rw----x. Now the question is only the members of Hr and Marketing group can view and edit the file. But the file is not accessible to the members of Finance Group. Can anyone tell me what would be the exact command for linux.root@localhost#<type the exact linux command>

3 Answers   Six Sigma,


How do I find my user id in linux?

0 Answers  


You need to see the last fifteen lines of the files dog, cat and horse. What command should you use?

0 Answers  


What does chmod 666 do?

0 Answers  






Categories