Logo

Programming-Idioms

Assign to x the string value of the first command line parameter, after the program name.
Implementation
Java

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Java implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "os"
x := os.Args[1]
$x = $ARGV[0];
void main(int argc, char *argv[])
{
    char *x = argv[1];
}
use std::env;
let first_arg = env::args().skip(1).next();

let fallback = "".to_owned();
let x = first_arg.unwrap_or(fallback);
auto x = args[1];
var
  _x: String;
begin
  _x := ParamString(1);
end.
main(args) {
  var x = args[0];
}
x = ARGV.first
x <- return.head =<< System.Environment.getArgs
import sys
x = sys.argv[1]
$x = $argv[1];
x = arg[1]
const x = process.argv[2]
static void Main(string[] args)
{
    string x = args[0];
}
  character(len=:), allocatable :: x
  integer :: n
  call get_command_argument (1, length=n)
  allocate (character(n):: x)
  call get_command_argument (1, x)
int main(int argc, char *argv[])
{
 vector<string> args(1 + argv, argc + argv);

 string x = args.at(0);
}
use std::env;
let x = env::args().nth(1).unwrap_or("".to_string());