Showing posts with label shell-scripts. Show all posts
Showing posts with label shell-scripts. Show all posts

Friday, October 17, 2008

Renaming Files in Linux

Type the following on commandline of a bash shell and change the logic as needed.


for i in `ls /home/ssinghal` ; do mv "$i" "$i.new" ; done

Wednesday, August 15, 2007

Getopts with bash


#!/bin/sh

usage()
{
echo "Usage: $0 -a all -b ball -c -d -e";
exit 1;
}

if [ $# -lt 1 ] ; then
usage;
fi

# ":" decides which options require an argument
# In the example below options "a" and "b" will require a value to be passed along
while getopts a:b:cde opt
do
case "$opt" in
a) echo "hello $OPTARG";;
b) echo "hello $OPTARG";;
c) echo "c is selected";;
d) echo "d is selected";;
e) echo "e is selected";;
\?) usage;;
esac
done