Ubuntu Suomen keskustelualueet
Ubuntun käyttö => Ohjelmointi, palvelimet ja muu edistyneempi käyttö => Aiheen aloitti: JJK - 26.06.08 - klo:21.36
-
Sain pitkän tuhrauksen jälkeen käännettyä ensimmaisen ohjelman lähdekoodista. ;D
Nyt sitten pitäisi ajaa sillä kaikki kansion tiedostot läpi. Mutta tiedostonimi tuottaa hieman ongelmia.
Eli kansiossa on
$ ls
11.dxf 12.dxf 13.dxf
Sitten aikani komentorivin kanssa puuhattuani olen saanut tällaisen komennon kirjoitettua. Mutta se kaipaa pientä viilausta.
for i in *.dxf; do vec2web "$i" "$i".png; done
Ja tuloksena on
ls
11.dxf 11.dxf.png 12.dxf 12.dxf.png 13.dxf 13.dxf.png
Eli noista png kuvien nimistä pitäis saada noi .dxf:t pois
-
for i in *.dxf ; do j=`echo $i | sed 's/.dxf//g'`; vec2web "$i" "$j".png; done;
otetaas vaikka sedillä pois .dfx.
-
for i in *.dxf ; do j=`echo $i | sed 's/.dxf//g'`; vec2web "$i" "$j".png; done;
otetaas vaikka sedillä pois .dfx.
Joo just sain ratkaistua tuonne toiseen topiciin antamasi esimerkin avulla
http://forum.ubuntu-fi.org/index.php?topic=19483.msg144860#msg144860 (http://forum.ubuntu-fi.org/index.php?topic=19483.msg144860#msg144860)
Nyt toimii. :) Kiitti.
-
for i in *.dxf ; do j=`echo $i | sed 's/.dxf//g'`; vec2web "$i" "$j".png; done;
otetaas vaikka sedillä pois .dfx.
Tai vaihtoehtoisesti homma voidaan tehdä hieman lyhyemmin ja yksinkertaisemmin.
$ for f in *.dxf; do vec2web "$f" "${f%.*}.png"; done
-
Tai vaihtoehtoisesti homma voidaan tehdä hieman lyhyemmin ja yksinkertaisemmin.
$ for f in *.dxf; do vec2web "$f" "${f%.*}.png"; done
Tarkoittaako tuo "${f%.*}", että muuttujasta f leikataan pisteestä eteenpäin muut pois?
Olisi ihan mielenkiintoista ymmärtää mitä tekee, että tämä ei mee ihan copy pasteksi.
-
Tarkoittaako tuo "${f%.*}", että muuttujasta f leikataan pisteestä eteenpäin muut pois?
Olisi ihan mielenkiintoista ymmärtää mitä tekee, että tämä ei mee ihan copy pasteksi.
Ei vaan muuttujan f lopusta leikataan lyhin mallia ".*" vastaava pätkä pois eli käytännössä leikataan pois viimeisestä pisteestä alkaen loppun. Jos prosenttimerkkejä olisi kaksi niin silloin lopusta poistettaisiin pisin mallia vastaava pätkä eli ensimmäisestä pisteestä loppuun saakka.
Kannattaa lukea bashin manuaalista Parameter Expansion -alaotsikon alainen teksti kokonaan. Alla on lainattuna muutama näppärä ominaisuus jotka ainakin on hyvä tuntea.
$ man bash
[...]
EXPANSION
[...]
Parameter Expansion
[...]
${parameter:offset}
${parameter:offset:length}
Substring Expansion. Expands to up to length characters of parameter starting at
the character specified by offset. If length is omitted, expands to the substring
of parameter starting at the character specified by offset. length and offset are
arithmetic expressions (see ARITHMETIC EVALUATION below). length must evaluate to
a number greater than or equal to zero. If offset evaluates to a number less than
zero, the value is used as an offset from the end of the value of parameter.
Arithmetic expressions starting with a - must be separated by whitespace from the
preceding : to be distinguished from the Use Default Values expansion. If parame‐
ter is @, the result is length positional parameters beginning at offset. If
parameter is an array name indexed by @ or *, the result is the length members of
the array beginning with ${parameter[offset]}. A negative offset is taken relative
to one greater than the maximum index of the specified array. Note that a negative
offset must be separated from the colon by at least one space to avoid being con‐
fused with the :- expansion. Substring indexing is zero-based unless the posi‐
tional parameters are used, in which case the indexing starts at 1.
[...]
${parameter#word}
${parameter##word}
The word is expanded to produce a pattern just as in pathname expansion. If the
pattern matches the beginning of the value of parameter, then the result of the
expansion is the expanded 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.
${parameter%word}
${parameter%%word}
The word is expanded to produce a pattern just as in pathname expansion. If the
pattern matches a trailing portion of the expanded value of parameter, then the
result of the expansion is the expanded value of parameter with the shortest match‐
ing 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 parame‐
ter 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.
${parameter/pattern/string}
The pattern is expanded to produce a pattern just as in pathname expansion. Param‐
eter is expanded and the longest match of pattern against its value is replaced
with string. If Ipattern begins with /, all matches of pattern are replaced with
string. Normally only the first match is replaced. If pattern begins with #, it
must match at the beginning of the expanded value of parameter. If pattern begins
with %, it must match at the end of the expanded value of parameter. If string is
null, matches of pattern are deleted and the / following pattern may be omitted.
If parameter is @ or *, the substitution 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 substitution operation is applied to
each member of the array in turn, and the expansion is the resultant list.
[...]