Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Jednostavan script pojasnjenje

[es] :: Skript jezici :: Jednostavan script pojasnjenje

[ Pregleda: 870 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Machiavelli...
Đorđe Đokanović
IT Support Engineer II
www.amazon.com
Philadelphia

Član broj: 90589
Poruke: 597
*.hsd1.pa.comcast.net.

Sajt: www.linkedin.com/in/dorde..


Profil

icon Jednostavan script pojasnjenje17.10.2011. u 03:47 - pre 1051 dana i 6h

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.

Having an idea is like being in a nutshell, but exchanging idea and collaborate
with
others is like being in infinite ocean of knowledge.
________________________________________________________________
____

Veruj u sebe. Ako ti neces, ko hoce?!
 
Odgovor na temu

uranium
Beograd

Član broj: 60097
Poruke: 539
95.180.61.*

Jabber: uranium@elitesecurity.org
ICQ: 324386953


Profil

icon Re: Jednostavan script pojasnjenje17.10.2011. u 04:59 - pre 1051 dana i 5h
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

Attempt all the problems. Those you can do, don't do. Do the ones you cannot.
 
Odgovor na temu

Machiavelli...
Đorđe Đokanović
IT Support Engineer II
www.amazon.com
Philadelphia

Član broj: 90589
Poruke: 597
*.hsd1.pa.comcast.net.

Sajt: www.linkedin.com/in/dorde..


Profil

icon Re: Jednostavan script pojasnjenje17.10.2011. u 05:18 - pre 1051 dana i 4h
Laptopovi

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!

Having an idea is like being in a nutshell, but exchanging idea and collaborate
with
others is like being in infinite ocean of knowledge.
________________________________________________________________
____

Veruj u sebe. Ako ti neces, ko hoce?!
 
Odgovor na temu

[es] :: Skript jezici :: Jednostavan script pojasnjenje

[ Pregleda: 870 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.