What is $1
in Bash (et al) is argv[1]
in a C program:
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc > 1)
{
printf("You provided at least one argument (or parameter)\n");
printf("The first argument is \"%s\"\n", argv[1]);
}
return 0;
}
The argument argc
is the number of valid entries in the argv
array. argv[0]
is the executable name, and you can access up to argv[argc - 1]
. (Actually you can access argv[argv]
as well, it is always a NULL
pointer).