Input Validation Shell Script

Technical, development No Comments »

I am Back but this time for some code sharing…..

I have been working on Unix Shell scripts for standalone work and came across the need for various types of input validation.

The basic need of Input validation comes when we have some other program’s depending on the input and those programs being sensitive to type of data  being send to them.

so i have compiled some neat hacks for this specific purpose….

You can check at the bottom for a detailed usage of the functions that i have created.

A direct download is also available here

function num_check()

{

read -p "$1" as

until expr $as - 1 >>/dev/null 2>/dev/null

do

read -p "$2 should be numeric please enter again" as

done

echo $as

}

function char_check()

{

read -p "$1" as

while expr $as - 1 >>/dev/null 2>/dev/null

do

read -p "$2 should not be numeric please enter again" as

done

echo $as

}

function null_check()

{

read -p "$1" as

while [ -z $as ]

do

read -p "$2 should not be null " as

done

echo $as

}

function alphacheck()

{

read -p "$1" as

while echo $as | grep [0-9!@#$%^&*()-_|] 2>>/dev/null >>/dev/null

do

read -p "$2 should be alphabet only" as

done

echo $as

}

#

#       sample calling for the script

#

#

#z=`num_check "Please enter the no" "Customer no" `

#echo $z

#echo `expr $z + 1`

#y=`char_check "Please enter the name" "Customer name"`

#echo $y

#echo $y | wc -c

#x=`null_check "Please enter enrollment no" "enrollment no"`

#q=`alphacheck "Please enter the name" "Customer name"`

#echo $q

I hope this helps someone

Waiting for comments and corrections……….

Working efficiently with VI / VIM

Technical 2 Comments »

vi or vim

for redhat based systems this doesn’t in any ways pose a difference as both vi and vim are on and the same thing (for more technical vi is aliased to vim).

but if you go to the other variants like debian or slackware these two software do show a difference in terms of evolution vi is what vi was and vim is what we always wanted vi to be.

so here I am presenting some more tips and tricks for better working inside vim

NOTE : most of these option work only in the command mode of vim until and unless explicitly specified

1) :sp <file_name>

split window splits the active vim window into two parts ….. if <file_name> is specified then in that case that particular file is being opened in the other half otherwise the same file is opened…….

2) this split windows can be easily managed by use of CTRL+W

3) :! <command>

this is a very useful option if you don’t want to leave the vi window and yet wish to work on command line for some help or other thing.

4) :set nu

this option can be a real timesaver when looking for errors

this gives number to each other.

5) :set ai

real timesaver for the programmers ai stands for auto indentation and not artificial intelligence :-)

6) :set tabstop=x

this yet is a programmers help ,

let you specify the  tab stopping which is by default 8 spaces

which can now be changed to x spaces

7) .vimrc The default config for your regular sessions.

if you wish to keep some options as constants what you can do is that you can just put all your general commands in a script file at ~/.vimrc………….

8 )  / for forward searching and ? for reverse searching….

9) most of us who are familiar with vi learned dd yy p and the basic commands

but P is also a paste facility with just one difference…..

when you use p you paste below the current line while P paste above the current line……..

10) sometimes you don’t want to change the binary data in a file or you have to work on binary files try

vim -b <file_name>

11)

we usually go on undoing stuff with “u” but what for redo….

CTRL + R is for the rescue…….

besides these if you are a programmer then you can leave aside the conventional “no file extension also works philosophy” asides just because this gives you a upper edge in vim with a proper syntax highlighting.

I HOPE THESE TIPS HELP YOU SOMEDAY

tips and tricks for debian newbies

Technical, debian No Comments »

1) vi is not working as expected, then please use vim, also if you wish to have context highlighting then remove “vim-tiny” and install “vim” and uncomment “syntax on” from /etc/vim/vimrc.

2) if you install wine the instead of trying to setup the environment on your own try wine-doors. (wine-tools is also a good tool but is now getting older and is unmaintained now also it seems to break a lot.)

3) you can try ies4linux to install ie6 its better then any thing.

4) to install MSI installer based apps use “msiexec /i”

5) to get color coded listing in shell uncomment the following line or add the following line in ~/.bashrc

alias ls=’ls –color=auto’
alias dir=’ls –color=auto –format=vertical’
alias vdir=’ls –color=auto –format=long’

6) if you try to unmount any device and its says device busy. then you have two options

a) umount -l <device_name>

b) for the second option you can check here

more tips to follow soon…………

Blog Hosted on Wordpress & WP Theme & Icons by N.Design Studio. Modified by Anant Shrivastava
Entries RSS Comments RSS Log in