Shell Script: Usage of Function inside shell script

#!/bin/sh

# file.sh: a sample shell script to demonstrate the concept of Bash shell functions

# define usage function

usage()

{

echo “Usage: $0 filename“; exit 1

}

# define is_file_exists function

is_file_exists()

{

f=”$1”

if [ -f “$f” ]

then

return 0

else

return 1

fi

}

# invoke  usage

if [ $# -ne 1 ]

then

usage

fi

# Invoke is_file_exists

#if ( is_file_exists “$1” )

is_file_exists “$1”

if [ $? -eq 0 ]

then

echo “File found”

else

echo “File not found”

fi
****

Thanks,
Ravi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: