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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho