Quantcast
Channel: What is the difference between $* and $@? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 12

Answer by x-yuri for What is the difference between $* and $@?

$
0
0

Most of the time you want $@. But a use I've found... Let's say you're creating a script that creates another script (e.g. to be executed on a remote server). You have an array with commands, and you want to pass $@ to the command:

f() {    cmds+=("some-command ${@@Q}")}f a b c

But this way 3 elements are added to the array: some-command a, b, and c. What you want is:

cmds+=("some-command ${*@Q}")

Or even:

cmds+=("some-command${@+ ${*@Q}}")

Viewing all articles
Browse latest Browse all 12

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>