Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Sending '*' as an argument

Posted by neo (The Architect), 27 July 2005
I 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.
Code:
if { $argc < 1 } {
   puts "Getting all files"
   set File_Name *
} else {
   set File_Name [lindex $argv 0];
}

Any help appreciated

Posted by admin (Graham Ellis), 27 July 2005
Are 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!)

Code:
[earth-wind-and-fire:WebServer/live_html/wellimg] grahamel% grep -c gubbing w*
grep -c gubbing wordmark.gif wp.jpg wt.jpg
wordmark.gif:0
wp.jpg:0
wt.jpg:0
[earth-wind-and-fire:WebServer/live_html/wellimg] grahamel%


Posted by neo (The Architect), 27 July 2005
It 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 2005
Hey 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 2005
If 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 2005
I just tried
script "*.c"
but saw that it took the first local .c file. Am I missing something?

Posted by admin (Graham Ellis), 27 July 2005
I 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.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho