ちょっとしたシェルスクリプト
をテンプレートにして作成
home
>
サイトマップ
開始行:
UNIX系OSの利点は,強力なコマンドライン処理にあります.コ...
#contents
* シェルスクリプトの実行方法 [#l1ca2954]
以下で紹介するスクリプトはbashとperlを使っています.だか...
$ chmod +x foo
とすることで実行属性がつきます.実行にはfooと同じディレク...
$ ./foo
とします.パスの通ったディレクトリに実行ファイルを置けば...
* 文字コード変換 [#i43ec43e]
LinuxのTeXは,日本語が入っている場合,その文字コードがEUC...
** Shift-JISに変換 [#l8ca16e6]
#!/bin/sh
while [ -n "$1" ]; do
if [ -e "$1" ]; then
TMPFILE=nkftmp$$
nkf --windows $1 > $TMPFILE
mv $TMPFILE $1
echo $1
fi
shift
done
** EUCに変換 [#b94b4e7e]
#!/bin/sh
while [ -n "$1" ]; do
if [ -e "$1" ]; then
TMPFILE=nkftmp$$
nkf --unix $1 > $TMPFILE
mv $TMPFILE $1
echo $1
fi
shift
done
* HTML関係 [#v27161f6]
HTMLファイルそのものはテキストファイルですから,正規表現...
** htm2html [#qbbda36b]
僕はHTMLを書きはじめた頃,拡張子を .htm としていました....
変更したいファイルが少しならファイル名を一つずつ変更して...
#! /bin/sh
test -z "$1" && echo "Usage: htm2html <directory>" && exit
cd "$1"
# .htm を .html に変換する
find . -maxdepth 1 -type f -name '*.htm' | while read ht...
echo "$htm" # 進行状況を表示
mv "$htm" `basename "$htm" .htm`.html
done
# HTMLファイルの内容を書き換える
find . -maxdepth 1 -type f -name '*.html' | while read h...
# HTMLファイルの内容をperlで置換
perl -i -p0777e "s/(<*\s.*?)(src=|href=)(['\"]?)(.*?...
done
最初のループは,find コマンドで拡張子が .htm のファイルを...
find で -maxdepth 1 としているので,サブディレクトリに関...
$ find . -type d -exec htm2html {} \;
と find コマンドから実行します.これはカレントディレクト...
** htmlconv-sjis [#v76dca6d]
UNIX系OSでの文字コードはEUCが標準なので,なにも考えずEmac...
#! /bin/sh
test -z "$1" && echo "Usage: htmlconv-sjis <directory>" ...
cd "$1"
# HTMLファイルの文字コードを変換する.
find . -maxdepth 1 -type f -name '*.html' | while read h...
echo "$html" # 進行状況を表示
# eucに変換
tmpfile=`basename "$html" .html`$$.html
nkf -s -Lw $html > $tmpfile
mv "$tmpfile" "$html"
done
# HTMLファイルのヘッダを書き換える.
find . -maxdepth 1 -type f -name '*.html' | while read h...
# perlで置換
perl -i -p0777e "s/(<meta\s.*?charset=)\w.*(['\"])/\...
done
このスクリプトは引数で指定したディレクトリ内の拡張子が .h...
** htmlconv-euc [#afc63b6b]
htmlconv-sjis をちょっと変更したら,EUC へ変換するものも...
#! /bin/sh
test -z "$1" && echo "Usage: htmlconv-euc <directory>" &...
cd "$1"
# HTMLファイルの文字コードを変換する.
find . -maxdepth 1 -type f -name '*.html' | while read h...
echo "$html" # 進行状況を表示
# eucに変換
tmpfile=`basename "$html" .html`$$.html
nkf -e -Lu $html > $tmpfile
mv "$tmpfile" "$html"
done
# HTMLファイルのヘッダを書き換える.
find . -maxdepth 1 -type f -name '*.html' | while read h...
# perlで置換
perl -i -p0777e "s/(<meta\s.*?charset=)\w.*(['\"])/\...
done
これらのスクリプトも,サブディレクトリに関してはいじりま...
** htmltex-arrange [#q17e483d]
LaTeXで書いた文書をHTMLに自動変換してくれるLaTeX2HTMLとい...
それと,僕はいつも <body> タグの直後に <div class="box"> ...
#! /bin/sh
test -z "$1" && echo "Usage: htmltex-arrange <directory>...
cd "$1"
find . -maxdepth 1 -type f -name '*.html' | while read h...
echo "$html"
perl -i -p0777e "s/<body\s.*?\w.*?>/<body><div class...
perl -i -p0777e "s/(<link\s.*?HREF=)(['\"]?)\w.*.css...
perl -i -p0777e "s/<\/body>/<\/div><\/body>/gi" "$ht...
done
このサイトの [[物理公式集:http://www12.plala.or.jp/ksp/fo...
-style cssのパス
で対応できます(HTMLにも手を加えたいなら,スクリプトで処...
** サイト引っ越し時のHTML生成 [#rbd079f1]
#!/bin/sh
BASEHREF=http://hooktail.org/sakima/125cc
while [ -n "$1" ]; do
if [ -e "$1" ]; then
TMPFILE=nkftmp$$
FILENAME=$1
URL=$BASEHREF/$FILENAME
: > $1
cat > $1 <<- END
<html>
<body>
<meta http-equiv="Content-Type" content="text/html; c...
<title>移転しました</title>
</head>
<body>
<p><a href="$URL">$URL</a> に移転しました m(_ _)m</p>
</body>
</html>
END
lv -Ou8 $1 > $TMPFILE
mv $TMPFILE $1
echo $1
fi
shift
done
* その他 [#b9c14330]
** raumen [#ga1a620e]
研究室での食事といえばカップラーメン. 3分後に音が鳴るア...
#! /bin/sh
sleep 160 && perl -e 'print "\x07"; print "Raumen is ava...
これを実行すると指定時間後にビープ音がピッと鳴ります.変...
* 参考リンク [#gb716860]
このページのシェルスクリプト書くにあたって,つぎのサイト...
- [[Unix Magazine連載:横着プログラミング 第11回:小粒な...
終了行:
UNIX系OSの利点は,強力なコマンドライン処理にあります.コ...
#contents
* シェルスクリプトの実行方法 [#l1ca2954]
以下で紹介するスクリプトはbashとperlを使っています.だか...
$ chmod +x foo
とすることで実行属性がつきます.実行にはfooと同じディレク...
$ ./foo
とします.パスの通ったディレクトリに実行ファイルを置けば...
* 文字コード変換 [#i43ec43e]
LinuxのTeXは,日本語が入っている場合,その文字コードがEUC...
** Shift-JISに変換 [#l8ca16e6]
#!/bin/sh
while [ -n "$1" ]; do
if [ -e "$1" ]; then
TMPFILE=nkftmp$$
nkf --windows $1 > $TMPFILE
mv $TMPFILE $1
echo $1
fi
shift
done
** EUCに変換 [#b94b4e7e]
#!/bin/sh
while [ -n "$1" ]; do
if [ -e "$1" ]; then
TMPFILE=nkftmp$$
nkf --unix $1 > $TMPFILE
mv $TMPFILE $1
echo $1
fi
shift
done
* HTML関係 [#v27161f6]
HTMLファイルそのものはテキストファイルですから,正規表現...
** htm2html [#qbbda36b]
僕はHTMLを書きはじめた頃,拡張子を .htm としていました....
変更したいファイルが少しならファイル名を一つずつ変更して...
#! /bin/sh
test -z "$1" && echo "Usage: htm2html <directory>" && exit
cd "$1"
# .htm を .html に変換する
find . -maxdepth 1 -type f -name '*.htm' | while read ht...
echo "$htm" # 進行状況を表示
mv "$htm" `basename "$htm" .htm`.html
done
# HTMLファイルの内容を書き換える
find . -maxdepth 1 -type f -name '*.html' | while read h...
# HTMLファイルの内容をperlで置換
perl -i -p0777e "s/(<*\s.*?)(src=|href=)(['\"]?)(.*?...
done
最初のループは,find コマンドで拡張子が .htm のファイルを...
find で -maxdepth 1 としているので,サブディレクトリに関...
$ find . -type d -exec htm2html {} \;
と find コマンドから実行します.これはカレントディレクト...
** htmlconv-sjis [#v76dca6d]
UNIX系OSでの文字コードはEUCが標準なので,なにも考えずEmac...
#! /bin/sh
test -z "$1" && echo "Usage: htmlconv-sjis <directory>" ...
cd "$1"
# HTMLファイルの文字コードを変換する.
find . -maxdepth 1 -type f -name '*.html' | while read h...
echo "$html" # 進行状況を表示
# eucに変換
tmpfile=`basename "$html" .html`$$.html
nkf -s -Lw $html > $tmpfile
mv "$tmpfile" "$html"
done
# HTMLファイルのヘッダを書き換える.
find . -maxdepth 1 -type f -name '*.html' | while read h...
# perlで置換
perl -i -p0777e "s/(<meta\s.*?charset=)\w.*(['\"])/\...
done
このスクリプトは引数で指定したディレクトリ内の拡張子が .h...
** htmlconv-euc [#afc63b6b]
htmlconv-sjis をちょっと変更したら,EUC へ変換するものも...
#! /bin/sh
test -z "$1" && echo "Usage: htmlconv-euc <directory>" &...
cd "$1"
# HTMLファイルの文字コードを変換する.
find . -maxdepth 1 -type f -name '*.html' | while read h...
echo "$html" # 進行状況を表示
# eucに変換
tmpfile=`basename "$html" .html`$$.html
nkf -e -Lu $html > $tmpfile
mv "$tmpfile" "$html"
done
# HTMLファイルのヘッダを書き換える.
find . -maxdepth 1 -type f -name '*.html' | while read h...
# perlで置換
perl -i -p0777e "s/(<meta\s.*?charset=)\w.*(['\"])/\...
done
これらのスクリプトも,サブディレクトリに関してはいじりま...
** htmltex-arrange [#q17e483d]
LaTeXで書いた文書をHTMLに自動変換してくれるLaTeX2HTMLとい...
それと,僕はいつも <body> タグの直後に <div class="box"> ...
#! /bin/sh
test -z "$1" && echo "Usage: htmltex-arrange <directory>...
cd "$1"
find . -maxdepth 1 -type f -name '*.html' | while read h...
echo "$html"
perl -i -p0777e "s/<body\s.*?\w.*?>/<body><div class...
perl -i -p0777e "s/(<link\s.*?HREF=)(['\"]?)\w.*.css...
perl -i -p0777e "s/<\/body>/<\/div><\/body>/gi" "$ht...
done
このサイトの [[物理公式集:http://www12.plala.or.jp/ksp/fo...
-style cssのパス
で対応できます(HTMLにも手を加えたいなら,スクリプトで処...
** サイト引っ越し時のHTML生成 [#rbd079f1]
#!/bin/sh
BASEHREF=http://hooktail.org/sakima/125cc
while [ -n "$1" ]; do
if [ -e "$1" ]; then
TMPFILE=nkftmp$$
FILENAME=$1
URL=$BASEHREF/$FILENAME
: > $1
cat > $1 <<- END
<html>
<body>
<meta http-equiv="Content-Type" content="text/html; c...
<title>移転しました</title>
</head>
<body>
<p><a href="$URL">$URL</a> に移転しました m(_ _)m</p>
</body>
</html>
END
lv -Ou8 $1 > $TMPFILE
mv $TMPFILE $1
echo $1
fi
shift
done
* その他 [#b9c14330]
** raumen [#ga1a620e]
研究室での食事といえばカップラーメン. 3分後に音が鳴るア...
#! /bin/sh
sleep 160 && perl -e 'print "\x07"; print "Raumen is ava...
これを実行すると指定時間後にビープ音がピッと鳴ります.変...
* 参考リンク [#gb716860]
このページのシェルスクリプト書くにあたって,つぎのサイト...
- [[Unix Magazine連載:横着プログラミング 第11回:小粒な...
ページ名:
home
>
Modified by
物理のかぎプロジェクト
PukiWiki 1.4.5_1
Copyright © 2001-2005
PukiWiki Developers Team
. License is
GPL
.
Based on "PukiWiki" 1.3 by
yu-ji
Powered by PHP 5.3.29HTML convert time to 0.002 sec.