2

What is the effect of putting "@" before something (like the path of a file containing classpath entries for a Java run command)?

I know it's something to do with file contents but as you can imagine trying to search for it on Google is a bit difficult. I can't locate a manpage that talks about it either.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
  • 1
    I think it means 'read the file nominated by this name (each line in the named file represents an entry)' instead of 'this is the entry'. – Jonathan Leffler Oct 23 '12 at 22:03
  • The tags suggest you are talking about the unix shell, the text suggests java. Please clarify. And please provide an example, even if it's cluttered. – Marian Oct 23 '12 at 22:16
  • @Marian it looks like he wants to run java program from command line, and he has "@" character in parameter for that java program. – Kamil Oct 23 '12 at 22:42
  • I definitely don't think it's java-specific, that's just the most easy-to-explain example I know. Since I don't understand what it does, I'm having trouble reducing it to a bare-bones example (and obfuscating any information that is company-secret). Also, I don't have the example command where it works available at the moment, it's just from memory. I'm actually trying to see if I can use the '@' symbol to perform a different task. – Sridhar Sarnobat Oct 23 '12 at 22:49
  • As @JonathanLeffler stated correctly "...each line ... represents an entry", you can collect Java command line arguments in a file and add them when starting a java app, e.g., java @path_to_arguments/args.txt my.app.Main – geri Nov 12 '20 at 10:05

4 Answers4

2

The @ character has no general meaning on the Unix command line. It has uses by some popular utilities. A command that begins with @ in a Makefile tells make not to echo the line before executing it. GNU Autoconf will substitute @-enclosed variables, such as @srcdir@, with their substitutions discovered by configure.

user4815162342
  • 141,790
  • 18
  • 296
  • 355
2

It can mean different things in different programs. As a convention @file at command-line could be interpreted as:

Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed. Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively. from ld docs for @file

jfs
  • 399,953
  • 195
  • 994
  • 1,670
1

From Bash Reference Manual:

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.

(...)

@

Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" …. If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).

(...)

You can use @ (at-sign) in parameter for any program without escaping.

If you have to pass something like this $@ in parameter - you have to escape only $ (dollar sign).

Kamil
  • 13,363
  • 24
  • 88
  • 183
0

Python argparse also has built-in support for @opts.txt to take CLI options from the file opts.txt if enabled with the fromfile_prefix_chars option: Which is the best way to allow configuration options be overridden at the command line in Python? The syntax is so insane however, with its potential for conflicts with an actual file named @myfile that it is seldom used. Saner version of it asked at: how to get argparse to read arguments from a file with an option rather than prefix

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985