Dealing with Arguments in Shell Script - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Dealing with Arguments in Shell Script

Share This

In C programming language, probably you have heard of command line arguments. In shell script, we can pass arguments in the similar way. The ith argument is received by $i, for example, the first argument is received by $1. The number of arguments is determined by $#.

Copy content of a file to another

In the following example, the name of the source and destination files are received as arguments.

#!/bin/bash if [ $# -eq 2 ] then cp $1 $2 else echo "Usage: program.sh <source_file> <dest_file>" fi

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.