diff --git a/exc02.sh b/exc02.sh deleted file mode 100755 index 26b48eb..0000000 --- a/exc02.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# Write an script that accepts a file name and a number as its parameter, -# Then return the content of that line number in that file. - - diff --git a/showline.sh b/showline.sh new file mode 100644 index 0000000..fbf3b8c --- /dev/null +++ b/showline.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Write an script that accepts a file name and a number as its parameter, +# Then return the content of that line number in that file. + +if [ $# -ne 2 ]; then + echo "Usage showline fileName lineNumber" + exit -1 +fi + +file=$1 +line=$2 + +if [ -e "$file" ]; then + totalLines=`wc -l $file | cut -d" " -f1` + if [ $line -le $totalLines ]; then + cat $file|sed -n "$line"p + else + echo "File exists but line does not exists!" + fi +else + echo "File does not exists!" +fi