Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing/passing command line arguments to a bash script - what is the difference between "$@" and "$*"?
    primarykey
    data
    text
    <p>I am using a bash script to call and execute a <code>.jar</code> file from any location without having to constantly enter its explicit path.</p> <p>The <code>.jar</code> requires additional variable parameters to be specified at execution, and as these can be anything, they cannot be hard coded into the script.</p> <p>There are 3 variables in total, the first specifies 1 of 2 actions that the <code>.jar</code> is to make, the second specifies a target file to enact this action on and the third specifies the name of a file that the action is to create.</p> <p>The script I am currently using is:</p> <pre><code>#!/bin/bash java -jar "C:\path\to\file.jar" "$1" "$2" "$3" </code></pre> <p>I know very little about bash scripting, but while searching for another answer to my woes (now fixed) I came across <code>"$@"</code> and <code>"$*"</code> when referencing command line arguments. Doing more searching brought me to this site: <a href="http://how-to.wikia.com/wiki/How_to_read_command_line_arguments_in_a_bash_script" rel="noreferrer">How To Wiki: How to read command line arguments in a bash script</a>, but I can't find any solid information about those arguments without having to wade through tons of advanced bash programming that is way above my head.</p> <p>So now that I have rambled on forever, my question is relatively simple:</p> <p>Can I replace <code>"$1" "$2" "$3"</code> with <code>"$@"</code> or <code>"$*"</code>, and if so which is the better one to use?</p> <p>Also what, if any, is the difference between those commands?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload