Simon Scott Simon Scott - 1 year ago 57
Linux Question

Creating a simple bash script that uses cat and has 3 arguments

I have this bash command I am using to cat the output of two java programs that take 1 parameter each into a file:

cat file.ext | java program1 argument1 | java program2 argument2 > argument3

argument3 is a optional and if it is not provided it should just be file.srtd

How can I create a bash script for this?

Answer Source

In bash, the variable $n is the n'th argument.

The variable $# is the number of arguments given by the user.

So you can do somthing like that:


if (( $# < 3 )) ; then

cat file.ext | java program1 $1 | java program2 $2 > $3

You can look here for more examples

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download