FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 12-24-2007, 08:36 PM
Nils Kassube
 
Default How do I represent a variable that will be a file name in a script?

John Toliver wrote:
> 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.

I don't know if you are referring to a bash script or if nautilus has a
special scripting language. However, if it is bash, the command line
parameters are "$1", "$2", "$3", etc. As an extra advice: you should
quote the filenames because otherwise there might be problems if there
are spaces in the filenames. E.g. a very simple program to copy files
would look like this:

#!/bin/bash
cp "$1" "$2"

If it is called "copy" it would be executed on the command line like this:

copy file1 file2

where file1 would be $1 and file2 would be $2.

> 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 <destinationpathfoldername>" it will copy
> all files starting with "f" that are executables to the path I
> specified. what are the equivalents of operators like "*.*",

In a bash script "*.*" would be files with at least one dot in the name.
Use "*" alone, if you mean any file. However, usually hidden files are not
included (hidden files start with a dot). There is no special extension
for executable files but executable files have special permissions. And
there is one more important difference to DOS / Windows: The DOS shell
gives the string "somepath*.exe" as a parameter to the program. A shell
script gets a list of files (including path if given on the command line)
because the shell expands the wildcards already, unless the command is
quoted on the command line.

> 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.

The vertical line is the same as in DOS / Windows.

> First what are these things called,

"*" and "?" are wildcards and "|" is a pipe.

> secondly where can I go
> to read about them?

Try the manual for bash which is available online at
<http://www.gnu.org/software/bash/manual/bash.html> or if you prefer a
paper manual, I recommend the O'Reilly book "Learning the bash shell" by
Cameron Newham & Bill Rosenblatt.


Nils

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 12-25-2007, 06:30 PM
"John Toliver"
 
Default How do I represent a variable that will be a file name in a script?

1. So as I understand it what I want to do more research on is the term called "regular expressions"?* I googled for "regular expressions" and got mixed results with something called "extended regular expressions"* is this related? (I can probably figure this part out on my own)


2. For my shred script I did this:
-------------------------------------------------------------------------------------------------------------
#!/bin/bash
shred -f "$1"
rm "$1"

-------------------------------------------------------------------------------------------------------------
This* 'appears' to have shredded the file and then deleted it.* It's weird but the first time I tested the script, I thought it was broken because the file remained on the desktop.* I tried to play it and found it was garbage data so I assumed 'shred' simply overwrites the file and then I added the second instruction to delete it afterwards.


Now the shred man page says if a setting in your etc/fstab file for the EXT3 is set a certain way then it's possible that the shredded file can be recovered...

My fstab file looks like this:
-------------------------------------------------------------------------------------------------------------

# /etc/fstab: static file system information.
#
# <file system> <mount point>** <type>* <options>****** <dump>* <pass>
proc*********** /proc********** proc*** defaults******* 0****** 0

# /dev/sda2
UUID=05c88919-02ac-4600-8314-60f526db279d /************** ext3* defaults,errors=remount-ro 0****** 1
# /dev/sda3
UUID=1326a60b-8ec3-48ef-a8a6-c32c72d7825e /home********** ext3*** defaults******* 0****** 2

# /dev/sda1
UUID=28DC714FDC7117F0 /media/sda1**** ntfs*** defaults,umask=007,gid=46 0****** 1
# /dev/sda4
UUID=bea4e226-c950-4213-9b79-0944af99dcb0 none*********** swap*** sw************* 0****** 0
/dev/scd0****** /media/cdrom0** udf,iso9660 user,noauto,exec 0****** 0

/dev/fd0******* /media/floppy0* auto*** rw,user,noauto,exec 0****** 0
-------------------------------------------------------------------------------------------------------------

So now would I need to edit something here in order to make the file unrecoverable if I use this script?


Thanks to all for the help.* I appreciate it.

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 09:47 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org