A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script that sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.
In this post, we will write a shell script to copy file1 to file2 that are taken from the input and display the errors, if any.
The first line contains two space-separated file-names: a and b
Print “done” if the file is copied successfully, else print “error”
The following is the shell script to add two numbers:
echo enter two files read f1 f2 if [ -s $f1 ] then if [ -r $f1 -a -w $f2 ] then cp $f1 $f2 echo done else echo no read or write permission fi else echo empty file or file does not exist fi
$ enter two files $ a b $ done
Let us know in the comments if you are having any questions regarding this shell script.
And if you found this post helpful, then please help us by sharing this post with your friends. Thank You