User:Kloonurm: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Kloonurm (talk | contribs)
Created page with '==Bash skript=='
 
Kloonurm (talk | contribs)
No edit summary
Line 1: Line 1:
==Bash skript==
==Bash==
 
==Skript==
<source lang="bash">
#!/bin/bash
#Author: Kaido Loonurm
#Kasutamine: add-license.sh [text or text file path] [path... or search parameter]
#Otsib faili esimeselt realt vastet, kui ei leia siis lisab faili agusesse etteantud rea
#Näide: add-author.sh "Author:John Smith" *.java
#Versioon 0.8
 
TEXT=$1
 
#Kontrollin kas on ette antud fail v6i tekstiline v22rtus
if [ -f $TEXT ]
then
license_text=`head -1 $TEXT`
 
else
license_text=$TEXT
fi
 
#leian vajalikud failid ja loen need masiivi
for f in $(find -type f -iname $2); do
#kontrollin kas faili alguses leidub etteantud string
file_beginning=`head -1 $f | grep "$license_text"`
 
#Kui stringi ei leitud siis lisan selle faili  algusesse
if [ $? -ne 0 ]; then
#Loen faili sisu muutujasse et faili sisu s2iliks esialgsel kujul
AJUTINE=`cat "$f"`
#Kleebin lisatava teksti ja vana teksti kokku
echo -e "$license_text" "\n" "$AJUTINE" > tmp.txt; mv tmp.txt $f
#annan teada millised failid muudeti
echo "Muutsin faili: $f"
fi
exit 0
</source>

Revision as of 17:58, 15 May 2011

Bash

Skript

#!/bin/bash
#Author: Kaido Loonurm
#Kasutamine: add-license.sh [text or text file path] [path... or search parameter]
#Otsib faili esimeselt realt vastet, kui ei leia siis lisab faili agusesse etteantud rea
#Näide: add-author.sh "Author:John Smith" *.java
#Versioon 0.8

TEXT=$1

#Kontrollin kas on ette antud fail v6i tekstiline v22rtus
if [ -f $TEXT ]
then
	license_text=`head -1 $TEXT`

else
	license_text=$TEXT
fi

#leian vajalikud failid ja loen need masiivi
for f in $(find -type f -iname $2); do
#kontrollin kas faili alguses leidub etteantud string
file_beginning=`head -1 $f | grep "$license_text"`

#Kui stringi ei leitud siis lisan selle faili  algusesse
if [ $? -ne 0 ]; then
#Loen faili sisu muutujasse et faili sisu s2iliks esialgsel kujul
AJUTINE=`cat "$f"`
#Kleebin lisatava teksti ja vana teksti kokku
echo -e "$license_text" "\n" "$AJUTINE" > tmp.txt; mv tmp.txt $f
#annan teada millised failid muudeti
echo "Muutsin faili: $f"
fi
exit 0