Tagged: bash

Using a Colon As A Bash Null Operator


references

The title of this entry is came from the referent entry.
본 entry의 제목은 위에 언급된 페이지의 것을 사용하였음을 밝힌다.

:

shellscript를 하나 만들 던 중 if 구문에서 thenelse 사이에 아무것도 하고싶지 않을 때 : 을 사용하면 되는 것을 배웠다.

if <condition>; then
    # todo...
    :
else
    echo i'm in else
fi

shellscript for grunt-init



#!/bin/sh
# by Jin Kwon <onacit_at_gmail.com>
# fetches all https://github.com/gruntjs/grunt-init-*.git repositories
# into to your ~/.grunt-init
# and (or) pull them all
# this script uses 'jq' command
gruntinit=~/.grunt-init
if [ ! -d $gruntinit ]; then
echo making directory $gruntinit
mkdir $gruntinit
fi
if which jq > /dev/null; then
# the command 'jq' is available
:
else
echo the command 'jq' not found!
exit 1;
fi
apiurl=https://api.github.com/search/repositories?q=grunt-init-%2Buser:gruntjs
curl -s $apiurl | jq -r '.items[].clone_url' |
{
while read cloneurl
do
echo —————————————-
name=`echo $cloneurl | sed 's/.*\/\(grunt-init-.*\).git$/\1/'`
echo name: $name
path=$gruntinit/$name
if [ ! -d $path ]; then
echo cloning $cloneurl into $path
git clone -q $cloneurl $path
else
echo pulling $path
git -C $path pull -q
fi
done
}


#!/bin/sh
# by Jin Kwon <onacit_at_gmail.com>
# fetches all https://github.com/gruntjs/grunt-init-*.git repositories
# into to your ~/.grunt-init
# and (or) pull them all
# this script uses 'jq' command
# this script accept two options
# one is 'simple' which configs to clone with simple name without 'grunt-init-' prefixes.
# and the other is 'sample' which configs to include *-sample.git
simple=false
sample=false
for arg in "$@"; do
case "$arg" in
"simple")
simple=true
;;
"sample")
sample=true
;;
*)
;;
esac
done
#echo simple: $simple
#echo sample: $sample
gruntinit=~/.grunt-init
if [ ! -d $gruntinit ]; then
echo making directory $gruntinit
mkdir $gruntinit
fi
if which jq > /dev/null; then
# the command 'jq' is available
:
else
echo the command 'jq' not found!
exit 1;
fi
apiurl=https://api.github.com/search/repositories?q=grunt-init-%2Buser:gruntjs
curl -s $apiurl | jq -r '.items[].clone_url' |
{
while read cloneurl
do
echo —————————————-
name=`echo $cloneurl | sed 's/.*\/\(grunt-init-.*\).git$/\1/'`
echo name: $name
if ! $sample; then
if [[ $name == *"-sample"* ]]; then
echo skipping a sample: $name
continue
fi
fi
if $simple ; then
name=`echo $cloneurl | sed 's/.*\/grunt-init-\(.*\).git$/\1/'`
echo using a simplified name: $name
fi
path=$gruntinit/$name
if [ ! -d $path ]; then
echo cloning $cloneurl into $path
git clone -q $cloneurl $path
else
echo pulling $path
git -C $path pull -q
fi
done
}

find all jar files and print


I thought I need to print some jar files’ entries in my Java ME SDK’s lib directory.

$ zipinfo -1 cldc_1.8.jar
META-INF/
...
java/util/logging/StreamHandler.class
$

Then I tried to store those output to a text file.

$ zipinfo -1 cldc_1.8.jar > cldc_1.8.jar.txt
$ cat cldc_1.8.jar.txt
META-INF/
...
java/util/logging/StreamHandler.class
$

Then I need to change line delimiters for Windows..

$ unix2dos.exe cldc_1.8.jar.txt
unix2dos: converting file cldc_1.8.jar.txt to DOS format...
$

I realized I can do this in one command.

$ zipinfo -1 cldc_1.8.jar | unix2dos > cldc_1.8.jar.txt
$

And, finally, I can print all jar files entries in a command.

$ for j in *.jar;do zipinfo -1 $j | unix2dos > $j.txt;done
$