顯示具有 shell 標籤的文章。 顯示所有文章
顯示具有 shell 標籤的文章。 顯示所有文章

2009年2月3日 星期二

Quick command-line Numeral Conversion within Shell

(hex)15A -> (dec)346

echo 'ibase=16;obase=A;15A' | bc

ibase = input base
obase = output base
the default notation for both is decimal
if you want to specify decimal for obase, you should use obase=A ( A in hex = 10 in decimal )
input number must be in upper case

2008年10月6日 星期一

Batch image resize script on Ubuntu

- be able to specify resolution of image
- create a folder to put resized images in


#!/bin/bash

printf "Batch Image Resize..\n"
read -p "width: " width
read -p "height:" height

[ -d resize/ ] || mkdir resize

ls -1 *.[jJ][pP][gG] | while read file
do
convert -scale ${width}x${height} "$file" resize/"$file"
[ -f "$file" ] && printf "$file\tOK\n"
done

2008年7月29日 星期二

3 methods to read text file line by line as variable in shell script of Unix

1.

while read var
do
..$var..
done < FILE

2.

cat FILE |
while read var
do
..$var..
done

3.

for var in `cat FILE`
do
..$var..
done