Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the name of an input file passed in by redirection?

Lets say I get something like this in Linux / Bash:

./my_program <input_file.in

is there a way in my code to check the name of my input file?

something like this?

if (strcmp(in,"desired_input_file_name.in")) {
   printf("success!!"\n);
}
like image 326
Liron Haber Avatar asked Jul 02 '20 13:07

Liron Haber


1 Answers

There is no portable simple way. Piping via < will redirect the contents of input_file.in to the standard input of my_program. Its the same as if you had typed the contents of the file. If you want to know the filename then you need to pass that, eg as command line argument:

./my_program input_file.in
like image 115
463035818_is_not_a_number Avatar answered Oct 22 '22 18:10

463035818_is_not_a_number