/* count.sh */
/*hello.txt is a sample file already in my system*/
echo "enter a file"
read fname
if [ -f $fname ]
then
echo "number of characters in a given file are `wc -c $fname`"
echo "number of words in a given file are `wc -w $fname`"
echo "number of lines in a given file are `wc -l $fname`"
fi
/home/anil/~$ sh count.sh
enter a file
hello.txt
number of characters in a given file are 23
number of words in a given file are 6
number of lines in a given file are 1
/home/anil/~$
Note: if is a conditional statement.
-f followed by a name checks whether the given name is file or not
-d followed by a name checks whether the given name is directory or not
-r followed by a name checks whether the given file name have read permission or not
-w followed by a name checks whether the given name have write permission or not
-x followed by a name checks whether the given name have execute permission or not
/*hello.txt is a sample file already in my system*/
echo "enter a file"
read fname
if [ -f $fname ]
then
echo "number of characters in a given file are `wc -c $fname`"
echo "number of words in a given file are `wc -w $fname`"
echo "number of lines in a given file are `wc -l $fname`"
fi
/home/anil/~$ sh count.sh
enter a file
hello.txt
number of characters in a given file are 23
number of words in a given file are 6
number of lines in a given file are 1
/home/anil/~$
Note: if is a conditional statement.
-f followed by a name checks whether the given name is file or not
-d followed by a name checks whether the given name is directory or not
-r followed by a name checks whether the given file name have read permission or not
-w followed by a name checks whether the given name have write permission or not
-x followed by a name checks whether the given name have execute permission or not
Unix operating system Linux operating system shell programming bourn shell kourne shell c shell difference between unix and linux operating system , history of UNIX, red hat operating system. UNIX OS architecture , kernel utility programs , file handling process handling inter process communication pipes shared memory message queues socket programming TCP/IP , UDP programming , One to One chat Application , Basic shell program to add two numbers , echo function , while loops clear gt lt le ge ne eq if fi while do done case array in unix strings , cut copy paste cat dir pwd getcwd chdir command read write stat lseek fstat flock mechanism.even or add program vi editor command ni vi editor command mode esc mode insert mode aa dd x :q :wq :w
No comments:
Post a Comment