Tuesday, March 26, 2013

Unix Commands

General Unix commands

* Identify the last Saturday in the current month
LASTSAT=$(cal|awk '{if (NF==7) {SAT=$7}};END{print SAT}')

* Looper commands
for x in $(eval echo "{1..$maxCount}}")
do
        echo "${x}" > /dev/null
done

for x in $(seq 1 ${maxCount})
do
        echo "${x}" > /dev/null
done

* Number of days between two dates
echo $(($(($(date -d "2010/06/01" "+%s") - $(date -d "2010-05-15" "+%s"))) / 86400))

* Timeout a command
timeout_f () {
    $1 &
    sleep $2
    kill $! # ends somecommand if still running
}

echo "Calling timeout"
timeout_f 'read answer' 10 && #need 2 &'s
echo "exited command"
echo "forked.." # happens immediately

Strip last character (which is a /
branchPath=$(echo ${branchPath%\/})


Check if variable is a number
if [ "${changeListNumber}" -ne "${changeListNumber}" 2> /dev/null ]
then
        echo "${changeListNumber} isn't a number"
        exit 1
fi

No comments:

Post a Comment