Home > OS >  What is the meaning of @ in command line "bash -c $(curl -L https://www.example.com/install.sh
What is the meaning of @ in command line "bash -c $(curl -L https://www.example.com/install.sh

Time:05-26

Today I got a message in telegram, somebody asked for the meaning "@", I don't know either. I ask here to satisfy my own curiosity as well.

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

CodePudding user response:

The syntax is:

bash -c <thescript> <$0> <$1> <$2> etc...

The @ is assigned to $0 positional parameter.

bash -c 'echo $0' @

It's typical to use -- or _.

From man bash:

   -c        If the -c option is present, then commands are read from the first non-option argument command_string.  If there  are
             arguments  after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to
             the positional parameters.  The assignment to $0 sets the name of the shell, which is used in warning and error  mes‐    
             sages.

For example:

$ bash -c 'invalid(line' @
@: -c: line 1: syntax error near unexpected token `line'
@: -c: line 1: `invalid(line'

$ bash -c 'invalid(line' something_else
something_else: -c: line 1: syntax error near unexpected token `line'
something_else: -c: line 1: `invalid(line'
  •  Tags:  
  • bash
  • Related