[Gutsy]How do I represent a variable that will be a file name in a script?
Michael R. Head
burner at suppressingfire.org
Mon Dec 24 22:52:33 UTC 2007
On Mon, 2007-12-24 at 15:39 -0500, John Toliver wrote:
> Hello,
>
> I'm not very good at scripting so I'm sorry if the description isn't
> as clear as it could be but I am trying to write a nautilus script
> for shredding a file. I want to be able to right click on the file I
> wish to destroy, select "scripts>shred" and the script then knows to
> act on this file. How do I represent a variable in Linux scripting?
> I think it should be the equivalent of "%1" in batchfile scripting on
> windows.
Arguments on the commandline are $1 $2 ... for the first, second, ...
word on the command line ($0 is the name of the program being run).
Other variables can be defined by simply putting using the '=' operator,
and references with the '$' operator:
FOO=bar
echo $FOO
You can try this out in the Terminal directly.
If you're making nautilus scripts, you should read up on the details
(which are different from normal shell scripts):
http://www.gnome.org/learn/users-guide/latest/gosnautilus-440.html
http://www.linux.com/feature/114134
> Second, I wish I knew how to describe this better but what does the
> terminal recognize as "operators" on files. In windows if I type:
> "copy <sourcepath>\f*.exe <destinationpath\foldername>" it will copy
> all files starting with "f" that are executables to the path I
> specified. what are the equivalents of operators like "*.*", the
> vertical line "|" that goes before the "more" command in windows
> terminal that splits output to a page at a time, and other such
> commands. First what are these things called, secondly where can I go
> to read about them?
There are two sorts of tools to match multiple files (or multiple
whatevers): globs and regexps.
What you describe is the "glob," where you type in some part of a name
and put '?' where you don't want any single character to be matched and
'*' where you'd like any sequences of characters matched. This is what
is done in the shell and in shell scripts. In addition to '*' and '?',
you can also use '[' and ']' to match from a specific set of characters.
For example [abc]* will match any name that starts with 'a', 'b', or
'c'.
http://www.faqs.org/docs/abs/HTML/globbingref.html
http://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
http://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
Other tools (such as perl, grep, sed, ...) use what is know as a
"regexp" (REGular EXPression) which comes from theoretical computer
science. Here you use '.', '?', '*', '[', '(' and some other operators
to form more powerful matching words. I won't go into them here, but you
can read up on them elsewhere.
> --
> Patience yields far greater results than brute force or rage ever
> could so relax......it's just life !!!
--
Michael R. Head <burner at suppressingfire.org>
http://picasaweb.google.com/demiri.head.wedding
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3259 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20071224/c86ec55d/attachment.bin>
More information about the ubuntu-users
mailing list