#!/bin/sh
i=0
while [ $i -lt 10 ]; do
    i=$((i + 1 ))
    if [ $(( $i % 2 )) -eq 0 ]; then
        continue
    fi
    echo $i
done

Check for a file's existence in shell script

if [ -e /etc/passwd ]; then  
  echo "/etc/passwd exists!"
fi

Read command line options in shell script

if [ "$1" = "-f" ]; then
  echo "-f specified on command line as first option"
fi

Functions

die () { echo $@ >&2; exit 1;}
die "Unknown error"

Run a command 100 times, without seq

x=100
while [ $x -gt 0 ]
do
command
x=$(($x-1))
done
 
bash_scripts.txt · Last modified: 2006/10/02 12:19 by gavin
 
Recent changes RSS feed Valid XHTML 1.0 Valid CSS Driven by DokuWiki