Passing an argument to a file in linux

34 views Asked by At

I was wondering if there was some way to pass an argument to a file when running it. For example, I am running a php file in Linux called createcsv.php which uses two MySQL tables, an old one named products_feburary and a new one named products_march. It then generates csv files with data that is in the March catalog and not in the Feburary one. Right now, when the month changes I would change the MySQL tabels by simply editing the files and changing products_feburary -> products_march and products_march -> products_april. I am simply wondering if there was some way to pass the MySQL tables to the file directly something like createcsv.php("products_feburary", "products_march") which would allow me to pass the months as paremeters without needing to edit the files. Note that, the names are stored as strings so I only need to pass them as text. I have tried researching this, but haven't found anything on the internet that indicates that this is possible. I am wondering if there is a way to do this or a package you can install that allows you to do this.

Update: Unfortunately, I had not seen the PHP Command Line Arguments and Options question. To make my question more specific and separate it from the other question, I am wondering for a nonexpert, if someone could give an example of code for how exactly to pass the argument in the command line and receive it in the file using either the $argv or getopt() methods. Based on the second answer, it seems you pass it as

php createcsv.php products_feburary products_march

but within the file I am having trouble with receiving the arguments in a way such as

$oldtable = (assign "products_feburary")
$newtable = (assign "products_march")

I am wondering if someone can provide a small Hello World type program that shows how to read the inputs from the $argv or getopt() methods.

0

There are 0 answers