[ Machiavelli... @ 17.10.2011. 03:47 ] @
Script radi savrseno, kratak je ali meni nije jasno nesto...

file1.txt
file2.txt
file3.txt

Script pravi derektorijume file1 file2 file3, zatim prebacuje file-ove u odgovarajuce direktorijume koji su kreirani shodno imenu file-a.


Citat:
#!/bin/bash

path=/home/bora/scripts/multidir

for f in $path/*.txt; do

dir=${f%.*}
mkdir "$dir"
mv "$f" "$dir"
done


Jel moze neko da mi pojasni ovo

Citat:
dir=${f%.*}


Nije mi jasno kako je ekstraktovao iz file1.txt samo file1. Vidim da je par karaktera, nisam programer, jednostavno ne razumem.
[ uranium @ 17.10.2011. 04:59 ] @
Pročitaj prvo ovo:

http://www.gnu.org/software/ba...html#Shell-Parameter-Expansion

Citat:

${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in filename expansion. If the pattern matches a trailing portion of the expanded value of parameter, then the result of the expansion is the value of parameter with the shortest matching pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ case) deleted. If parameter is ‘@’ or ‘*’, the pattern removal operation is applied to each positional parameter in turn, and the expansion is the resultant list. If parameter is an array variable subscripted with ‘@’ or ‘*’, the pattern removal operation is applied to each member of the array in turn, and the expansion is the resultant list.


A evo i nekoliko primera koji će, nadam se, pomoći da razumeš:


f="abc.delete-me.txt"
echo ${f%*delete-me*}
abc.
# matchovan je i uklonjen samo trailing deo stringa



f="abc.delete-me.txt"
echo ${f%%*delete-me*}
# matchovan je i uklonjen ceo string



f="abc.delete-me.txt"
echo ${f%*delete-me}
abc.delete-me.txt
# nije matchovan trailing deo stringa



f="abc.delete-me.txt"
echo ${f%%*delete-me}
abc.delete-me.txt
# nije matchovan trailing deo stringa
echo ${f%%c.delete-me*}
ab
[ Machiavelli... @ 17.10.2011. 05:18 ] @
Upravo sam bio na http://www.gnu.org/s/bash/manual/bash.html

Hvala mnogo

Code:
f="abc.delete-me.txt"
echo ${f%*delete-me*}
abc.
# matchovan je i uklonjen samo trailing deo stringa


Jasno ko dan!