Sending '*' as an argument
Posted by neo (The Architect), 27 July 2005I have written a script that automates FTP'ing of files.
When I give it a filename as an argument it gets only that file.
When I do not specify a filename and just issue the script name it automatically FTP's all files (mget *) from the remote dir.
I just tried executing the script with '*' as an argument and I see that it tried to do an mget wiht a local filename.
I want to know how I can check for the '*' as an arg.
Here is the part I use to check if I should get all files or a specific one.
Any help appreciated
Posted by admin (Graham Ellis), 27 July 2005Are you running the script from a Unix of Linus shell? If so, giving a * as the parameter to the shell will be expanded by the shell into a list of file names handed to the script - the sctipt won't actually receive the *, so won't pass it on as a part of the mget command
Here's an example. I've run a grep command using a * in one of my parameters (under a C shell with the -x option which tells me the command that's really being run!)
Posted by neo (The Architect), 27 July 2005It is from a Linux BASH shell.
Ok so I guess I'll just document that it should be used without options for all files and never to use '*' as an arg.
Posted by neo (The Architect), 27 July 2005Hey does that mean that a *.c will also expand the same way?
Ohmi gosh! Then the only way this should work is with the correct given filename?
Is there any other way around this?
Posted by admin (Graham Ellis), 27 July 2005If you quote the option at the Unix / Linux shell, then it won't do the expansion:
myprog *.c ... runs "myprog" with - potentially - lots of parameters
myprog "*.c" ... runs "myprog" with a single parameter *.c
Posted by neo (The Architect), 27 July 2005I just tried
but saw that it took the first local .c file. Am I missing something?
Posted by admin (Graham Ellis), 27 July 2005I guess it also depends on what you're doing with the File_Name variable in your script. Try adding in a few puts statements and learn what's happening that way.
By the way - note that many Unix / Linux shells usually interpret the metacharacters in the likes of *.c, but if there's no match they will pass through the unaltered string. Also note that the *.c (or whatever it is) matches existing files, so on a Unix of a Linux system you CANNOT write
cp *.txt *.bak
to create a backup of every .txt file in the current directory, even though the command
copy *.txt *.bak
will work on MsDos / Dos / Windows systems.
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho