What is %1 in Programming?

%1 is a placeholder for the first argument in many programming languages. It can also be used to represent the current directory, or as an input prompt when setting interactive commands.

In programming, % means to substitute the text in brackets for what is inside it. So when you see “%s” in a program and put your cursor after it, this would mean that whatever follows (the string) should be replaced by “%s.” So in most cases, “%1” can be understood as first argument.

Example in a batch file

When used in a script, or command line, %1 is a variable that represents data from the input queue. For example, in a batch file, %1 can print what has been typed.

example.bat file content:

@echo off
echo Hello %1

If we run the command example.bat TLDevTech, it will print out “Hello TLDevTech”.

Example in PHP

In a PHP format function, %1 stands for first argument.

$format = '%2$s is %1$d years old';
echo sprintf($format, 20, 'John');
//output: John is 20 years old.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top