what is the command To print script arguments

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

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

1491


How do I check cpu usage?

566


How do I check my system performance?

550


How do you limit memory usage for commands?

563


How does diff command work?

495






What is mask and umask in linux?

527


Brief about the command nn?

597


How to hide the partition in grub booting?

541


How do I run multiple commands in linux?

526


How do I remove a soft link in linux?

500


What is the difference between clang and llvm?

553


How do I find the process id in linux?

516


Which command reduces the size of a file?

576


How use linux command line?

513


How do I clear terminal command history?

553