I found this script earlier, which initially was trying to resize ALL files.. mp3 and what not (because of the FILES=* I'm guessing):
I suppose you are generally interested in learning to write shell scripts and not only to make the script going you are attempting to write. Therefore a little explanation why this (any other constructs similar to this) is a VERY BAD IDEA and you should never do it:
The "*" is interpreted by the shell first and replaced with its result: a list of all entries in the current directory. It is never a good idea to work with relative pathes inside a script. Execute a scriptin another path and this might mix up everything and render your system unusable.
Aside from this: say the directory contains 3 entries, "fileA", "fileB" and "fileC", then the line would be equivalent to:
The first problem is: not all entries in a directory have to be files. There are directories, links, FIFOs and more. Chances are your "convert" utility does not know how to handle them at all because it is built to work with a certain type of files and nothing else.
Another problem is: suppose you have lots of such files. A UNIX directory can easily handle millions of files (i have a few such systems). Imagine what your for-loop will do when it is presented this line:
The shell will simply give up and issue an "too many arguments"-error.
This is why such for-loops are never correct and always to be avoided. If you want to cycle through a list of files do it this way:
If you want to modify your list you can either use shell-globs (*,?, ...) or text-filters to alter the list. For example, filter out every file with a number in the filename:
Now, back to your problem, for which the find-command is the correct wa to do it.
Quote:
Originally Posted by mozzles
As far as making it work on all subdirectories as well, I couldn't find much on that, but I did manage to read that I could do this....
When I tried changing "convert -thumbnail 235x $f sm_$f" to "convert -thumbnail 235x $f $f_small", it was a no-go.
Yes, because $f_small would be the content of a (non-existent) variable named "f_small". You can do whyt you want to do, but you need "variable expansion" for this, which is a bit complicated and probably not the first thing you want to learn.
For the sake of completeness, here you are:
Quote:
Originally Posted by mozzles
1. Specify multiple filenames to target, in the FILES= or otherwise...
There are two ways to achieve this: put in multiple "-name"-clauses into the find-statement:
A second way is, when the names are related enough, to construct a single name-clause with a wildcard:
Would find all files named "Folder.jpg" or "folder.jpg", for instance.
im trying to run the below if command
ifconfig -a |grep 10.100.120.21
gives me below output
inet addr:10.100.120.21 Bcast:10.100.120.255 Mask:255.255.255.0
i just want a basic shell which says if above exists then continue
how would i do this? (6 Replies)
Hi All,
I am new to shell scripting.
I have a variable which holds a numeric value.I have to check whether this variable holds a value between(0- 8),(8-17)(17-24).How do i write this syntax using if in shell scripting.
Thanks
Vignesh (2 Replies)
hi,
I am new script learner,
so my basic doubt is ,
how to store value of any command in a variable example
$ ls | wc -l
i want to stote the output of this in a variable c.
so that i can use c in if else loop.
and when do we use " ` " symbol in script..
can anyone also tell for... (5 Replies)
Lets say I wanted to create a script that would show what people are doing on my machine using the w command and refresh in about 6 seconds. What would be the easiest way to do this? I pretty much want the script to loop until I stop it.
I'm using the BASH shell by the way.
Help is appreciated.... (1 Reply)
Im trying to make a script that simply adds a word to the last available line in a txt file without overwriting any previous lines.
Ive googled this and there are great examples but no one explain what each function does, and i dont entirely understand how it works.
Basically Im looking for... (7 Replies)
I have two shell scripts in the different directories listed below,
/root/dev/dir1/test.sh
/root/dev/dir2/master.sh
I am executing the master.sh script from the test.sh like below and getting 'Permission denied' error.
#! /bin/sh
#test.sh
path='/root/dev'
$path/dir2/master.sh
But it... (2 Replies)
I need to have a script read a file that has a list of words in a single column like below:Black
Blue
Brown
Orange
Red
Yellow
Green
White
Purple
Silver
Grey
Tan
Then print to another file just all of the two-word possible combinations. Example:
Black,Blue
Anyone want to take a... (4 Replies)
Hello,
This is basic (i think). I am trying to run a shell script which would go into each folder (folder names defined in the list) and after entering would run some commands, once done, come out of the folder and continue until the list ends.
Pretty basic and there are bunch of example online. ... (9 Replies)
Hi everyone, first time visitor to these forums here.
Keeping a long story short I've been attempting to learn how to code in bash. I have VERY little previous experience with coding languages besides simply copying and pasting batch scripts for Windows. So, with that in mind I've followed a... (4 Replies)