2015
06
09

bash で for文やwhile文を1行で書く

for i in {1..10}; do echo $i; done

while true; do echo 'hello'; done
Comment



Only the blog author may view the comment.

[5]

本文が英数字のみの場合は書き込めません。

FILE=$1

Lines=`wc -l < $FILE`
CurrentLine=2
while [ $CurrentLine -lt $Lines ]
do
((CurrentLine++))
LINE=`tail -$CurrentLine $FILE | head -1`
j=0
for i in $LINE
do
((j++))
if [ $j -eq 3 ]
then
echo -n $i" "
fi
done
done
echo

[6]

コメント投稿確認


#!/bin/bash


if [ $# -ne 1 -o ! -d "$1" -o ! -r "$1" ]; then
echo ERROR
exit 1
fi

NFiles=`ls -l $1 | wc -l`
echo $NFiles

VAR=`ls -l $1 | tr -s " " | cut -d" " -f5`
RET=0
for S in $VAR
do
((RET = $RET + $S))
done

echo $RET

[7]

※印は必須項目です。


#!/bin/bash

set `cat $1`
TIMES=$1
SEC=$2
OUT=$3
BAK=$4
NUM=$5
ERR=$6

# flag to tell if mail message has been sent
MAILSENT=0

if [ -f $OUT ]
then
#if the maximum number of backups already exists,
#delete the last one to make way for the next run-through
if [ -f $OUT.$BKPNUM ]
then
rm $OUT.$BKPNUM
fi

#rename each existing backup file with the next higher numbered extension
while [ $BAK -ge 1 ]
do
NEXT=`expr $BAK + 1`
mv $OUT.$BAK $OUT.$NEXT 2>$ERR
((BAK--))
done

#rename the already existing output file with an extension of 1
mv $OUT $OUT.1 2>>$ERR
fi

while [ $TIMES -gt 0 ]
do
USERNUM=`who | wc -l` #number of users currently logged in
DATE=`date`
#if number of current users >= the max set in the config file, send email
if [ $USERNUM -ge $NUM -a $MAILSENT -eq 0 ]
then
`echo Number of users exceeded: $USERNUM at $DATE | mail $USER`

echo "Max number of users met. Emailing $USER."
MAILSENT=1 #change the variable so mail is not sent more than once
fi
(echo $DATE Users=$USERNUM) >> $OUT
((TIMES--))
sleep $SEC
done

[74]

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something.

I think that you could do with a few pics to drive the message home a little bit, but instead of
that, this is fantastic blog. A fantastic read.
I'll definitely be back.

Trackback
Trackback URL

«  | HOME |  »

奇妙な風景 Unique Scene
<< >>

プロフィール


最新記事


最新コメント


最新トラックバック


月別アーカイブ


カテゴリ


スポンサード リンク


FC2カウンター


検索フォーム


RSSリンクの表示


リンク


ブロとも申請フォーム


QRコード