sh

シェルで拡張子変更

sh

markdown を md に変更してみる % for i in *.markdown; do mv $i ${i%markdown}md; done

OSTYPE

sh

echo ${OSTYPE%%[^a-z]*}

パスが設定されていなかったら設定

sh

echo "$PATH" | grep -Fqv "$my_path" && export PATH="$my_path:$PATH"

php 切り替え

pearの設定 alias pear='pear -C /usr/local/php/etc/pear.conf $@' alias pearpear=pear

SomaFm

~/bin/somafm #!/bin/sh play() { osascript -e 'tell app "iTunes" to open location "'${1}'"' echo "play [ ${2} ]" } case $1 in stop) osascript -e 'tell app "iTunes" to stop' echo 'iTunes stop.' ;; help) echo "Usage: $0 {|help|stop|jazz|goa}"…

Firefoxをリロード

sh

id:oppara:20080320 重い...http://github.com/bard/mozrepl/wikis/home http://simile.mit.edu/wiki/Fresno % fresno -p http://d.hatena.jp/oppara

文字コードを変換

sh

同じディレクトリ内の、euc-jp(cp51932) な *.txt を utf-8 に変換し、*.utf8.txtにリネーム。 オリジナルは取っておく。 nkf % for file in *.txt; do for> nkf -w8 $file > ${file%.txt}.utf8.txt for> done % for file in *.txt; do for> nkf --ic=CP5193…

ブラウザをリロード

Safari osascript -e 'tell app "Safari"' -e 'activate' -e 'do JavaScript "window.location.reload();" in first document' -e 'end tell' Firefox System Eventsを使うので、「システム環境設定 -> ユニバーサルアクセス」の「補助装置にアクセスできる…

chhost?

Dynamic DNS用 #!/bin/sh # en1(airmac)は自宅 en=`/sbin/ifconfig en1 | /usr/bin/grep 192.168` case "$en" in *inet* ) # sudo cp -f /etc/hosts.home /etc/hosts sudo nicl . -create /machines/oppara.dynamic sudo nicl . -append /machines/oppara.dy…

ストリーミングの情報

applescript tell application "iTunes" current stream title -- the name of the current song in the playing stream name of current track -- the URL of the playing stream or streaming web site end tell shell script #!/bin/sh # osascript -e 't…

一意のプレイリストを再生

property thePlaylist : "IndiePopRocks" tell application "iTunes" launch stop set the_playlist to user playlist thePlaylist set view of front window to the_playlist play the_playlist end tell そのシェルスクリプト版 #!/bin/sh PLAY_LIST='Indi…

パイプ

sh

pipe.sh #!/bin/sh if [ -p /dev/stdin ]; then cat - fi % echo 'hoge'|/path/to/pipe.sh

ユーザー追加

#!/bin/sh USER=$1 PASS=$2 USERADD=`which useradd` PERL=`which perl` if [ $# -lt 2 ]; then cat <

windowsのファイルのパーミッションを整える

sh

共有サーバからコピーしてきたwindowsのファイルのパーミッションを整える。 Thumbs.dbを削除しとく。 #!/bin/sh d=`pwd` find "$d" -type f -name 'Thumbs.db' | xargs rm find "$d" -type f | xargs chmod 0644 find "$d" -type d | xargs chmod 0755 echo…

対話・引数

sh

対話 echo 'Get it? [y/n]' read ANS if [ $ANS = 'y' -o $ANS = 'yes' ]; then echo 'ゴリ.' else echo '...' fi 引数 if [ -z $1 ]; then echo "Usage: $0 xxx" else echo $1 fi exit 0

ヒアドキュメント

最初のEOFをシングルクォートで挟むと変数は展開されない。 shell cat <

○日以上経過したログを削除

sh

".log"という文字列をもつTMPPATHディレクトリにあるファイルで、7日以上経過したものを TMPPATH='path/to/' AGED=7 find ${TMPPATH} -mtime +$AGED | grep "?.log" | xargs rm -f

インプットメソッド切替

むちゃ遅 むちゃ環境依存(日頃、cmd+spaceを使用してる人向け) より詳しくは、 defaults -currentHost read com.apple.HIToolbox AppleCurrentInputSourceして"Input Mode"で種別を判断する。 applescript版 property ROMAN : "smRoman" set IM to do shel…

shellスクリプトの構文チェック

$ /bin/sh -n file